文本方向在NSOutlineView中位于顶部

时间:2015-02-14 00:08:50

标签: cocoa swift storyboard nsoutlineview

我有一个NSOutlineView来显示和编辑键值对。如果值环绕,则键垂直居中。 我希望两个文本都从第一行开始。

enter image description here

如何把它们放在首位?在故事板中的Code oder中。 谢谢你的提示。

更新 这是渲染代码,也许我必须添加一个NSLayoutConstraint?能给我举个例子?

func outlineView(outlineView: NSOutlineView,
    heightOfRowByItem item: AnyObject) -> CGFloat {
        let node = item as JSONDataNode
        let col: NSTableColumn = outlineView.outlineTableColumn!
        let cell: NSCell = col.dataCell as NSCell
        cell.stringValue = node.getString()
        let height = cell.cellSizeForBounds(NSMakeRect(0.0, 0.0, col.width, 1000.0)).height
        return height
}

func outlineView(outlineView: NSOutlineView, viewForTableColumn tableColumn: NSTableColumn?, item: AnyObject) -> NSView? {

    let node = item as JSONDataNode

    var cell = NSTableCellView()

    if tableColumn?.identifier == "NAME_COLUMN" {
        cell = outlineView.makeViewWithIdentifier("NAME_COLUMN", owner: self) as NSTableCellView
        cell.textField!.stringValue = node.key
        cell.textField!.editable = true
        cell.textField!.delegate = self

    } else
        if tableColumn?.identifier == "VALUE_COLUMN" {
            cell = outlineView.makeViewWithIdentifier("VALUE_COLUMN", owner: self) as NSTableCellView
            cell.textField!.stringValue = node.getString()
            cell.textField!.editable = true
            cell.textField!.delegate = self
    }

    return cell
}

1 个答案:

答案 0 :(得分:0)

我有一个

outlineView.rowSizeStyle    =   NSTableViewRowSizeStyle.Small

在我的viewDidLoad中做了这个伎俩。删除此行后,文本将显示在行的顶部。

文档说:

The table will use a row height specified for a small table. It is     
required that the size be fully tested and supported if 
NSTableViewRowSizeStyleCustom is not used.
嗯,'mkay。