我尝试使用 NSGridView 像这样布局 NSTableCellView
class GridItemCV: NSTableCellView
{ var grid : NSGridView? = nil
let empty = NSGridCell.emptyContentView
var tf = NSTextField()
override init(frame frameRect: NSRect)
{ super .init(frame: frameRect)
setup()
}
required init?(coder decoder: NSCoder)
{ super .init(coder: decoder)
setup()
}
func setup()
{ self.translatesAutoresizingMaskIntoConstraints = false
tf.translatesAutoresizingMaskIntoConstraints = false
grid = NSGridView( views: [
[empty, empty],
[empty, tf]
])
grid?.translatesAutoresizingMaskIntoConstraints = false
self.addSubview(grid!)
grid?.leftAnchor.constraint(equalTo: self.leftAnchor).isActive = true
grid?.rightAnchor.constraint(equalTo: self.rightAnchor).isActive = true
grid?.topAnchor.constraint(equalTo: self.topAnchor).isActive = true
grid?.bottomAnchor.constraint(equalTo: self.bottomAnchor).isActive = true
}
我的问题。
应该由 Interfacebuilder 连接的属性 textField 尚未在构造函数中实例化。我什么时候可以访问该物业?