View-based NSOutlineView without NIB?

后端 未结 3 1557
难免孤独
难免孤独 2020-12-31 21:44

NSOutlineView is a subclass of NSTableView. And currently, NSTableView supports two implementations.

  • Cell-based.
3条回答
  •  庸人自扰
    2020-12-31 22:24

    In addition to @jeberle 's answer, I need to note something more.

    • The key to keep the text-field and image-view is adding them as subviews of the NSTableCellView.

    • Set NSTableView.rowSizeStyle to a proper value (non-Custom which is default value) to make the table-view layout them automatically. Otherwise, you have to layout them completely yourself.

    • Do not touch frame and autoresizing stuffs if you want to use predefined NSTableViewRowSizeStyle value. Otherwise, the layout might be broken.

    • You can adjust row-height by providing private func outlineView(outlineView: NSOutlineView, heightOfRowByItem item: AnyObject) -> CGFloat delegate method. Setting NSTableView.rowHeight is not a good idea because it needs NSTableView.rowSizeStyle set to Custom which will turn off cell text/image layout management provided by default.

    • You can reuse row/cell views by settings NSView.identifier property. (example)

提交回复
热议问题