gpt4 book ai didi

swift - NSTableCellView 与 NSGridView

转载 作者:行者123 更新时间:2023-11-30 11:49:27 26 4
gpt4 key购买 nike

我尝试使用 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 尚未在构造函数中实例化。我什么时候可以访问该特性?

最佳答案

我找到了解决方案。

在中构建 NSGridView

awakeFromNib() 

我可以访问从 Interfacebuilder 连接的属性 textField

关于swift - NSTableCellView 与 NSGridView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48490426/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com