0

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

4

1 回答 1

0

我找到了解决方案。

在中构建 NSGridView

awakeFromNib() 

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

于 2018-01-29T19:54:13.883 回答