0
votes

This question is an extension to this question.

I am working on Cocoa App, where I am populating a table using Cocoa Bindings.

I am subclassing NSView instead of NSTableCellView

As per NSTableCellView Class Referenence

If you use your own custom view cells that are not based on NSTableCellView you should implement this property(objectValue) in order to be able to receive changes to cell values.

Also

swift
var objectValue: AnyObject?
The objectValue is automatically set by the table when using bindings or is th...


This is my class implementation, which I will be using as cell in TableView

class TestView : NSView {
    var objectValue: AnyObject?

    init(nameA: String, nameB: String) {
        super.init(frame: NSMakeRect(3, 3, 300, 40))

        objectValue = nameA
        let firstName = MyTextField(location: NSMakePoint(10, 10), stringVal: nameA)
        self.addSubview(firstName)

        let secondName = MyTextField(location: NSMakePoint(250, 10), stringVal: nameB)
        self.addSubview(secondName)
    }

    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
}

Although having declared the objectValue in TestClass, I am still not able to bind the object value from IB

1

1 Answers

2
votes

Custom views and objects don't get custom property bindings in IB. YOU HAVE TO SET UP BINDINGS IN CODE.

You also need to ensure your class does all the fun stuff required to enable bindings.