简体   繁体   English

子类NSView而不是NSTableCellView

[英]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 . 我正在使用Cocoa App,在其中使用Cocoa Bindings填充表格。

I am subclassing NSView instead of NSTableCellView 我在继承NSView而不是NSTableCellView

As per NSTableCellView Class Referenence 根据NSTableCellView类参考

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. 如果您使用自己的不基于NSTableCellView的自定义视图单元格,则应实现此属性(objectValue),以便能够接收对单元格值的更改。

Also

swift 迅速
var objectValue: AnyObject? var objectValue:AnyObject?
The objectValue is automatically set by the table when using bindings or is th... 使用绑定时,表会自动设置objectValue,否则,...


This is my class implementation, which I will be using as cell in TableView 这是我的类实现,将在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 尽管已经在TestClass中声明了objectValue ,但我仍然无法从IB绑定对象值

Custom views and objects don't get custom property bindings in IB. 自定义视图和对象在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. 您还需要确保您的班级完成了启用绑定所需的所有有趣的工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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