简体   繁体   中英

Subclass NSView instead of NSTableCellView

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM