【问题标题】:NSTableCellView with NSGridViewNSTableCellView 与 NSGridView
【发布时间】:2018-01-28 19:26:59
【问题描述】:

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

【问题讨论】:

    标签: swift cocoa nstableview nsview nstablecellview


    【解决方案1】:

    我找到了解决办法。

    中构建NSGridView
    awakeFromNib() 
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-23
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多