我正在使用NSOutlineView
,一切正常,单击表格单元格时可以进入编辑模式。
但是,我想在插入新行时自动进入编辑模式。
我玩过makeFirstResponder
方法,但它不起作用。
这是我所做的:
// -------------------------------------------------------------------------------
// viewForTableColumn:tableColumn:item
// -------------------------------------------------------------------------------
func outlineView(_ outlineView: NSOutlineView, viewFor tableColumn: NSTableColumn?, item: Any) -> NSView? {
var result = outlineView.make(withIdentifier: tableColumn?.identifier ?? "", owner: self)
if let node = (item as! NSTreeNode).representedObject as? BaseNode {
if self.outlineView(outlineView, isGroupItem: item) { // is it a special group (not a folder)?
// Group items are sections of our outline that can be hidden/shown (i.e. PLACES/BOOKMARKS).
let identifier = outlineView.tableColumns[0].identifier
result = outlineView.make(withIdentifier: identifier, owner: self) as! NSTableCellView?
let value = node.nodeTitle
(result as! NSTableCellView).textField!.stringValue = value
} else if node.isSeparator {
result = outlineView.make(withIdentifier: "SeparatorView", owner: self)
} else {
(result as! NSTableCellView).textField!.stringValue = node.nodeTitle
(result as! NSTableCellView).imageView!.image = node.nodeIcon
if node.isLeaf {
let textField = (result as! NSTableCellView).textField!
(result as! NSTableCellView).window?.makeFirstResponder(textField)
textField.isEditable = true // make leaf title's editable.
//### Translator's extra
textField.target = self
textField.action = #selector(self.didEditTextField(_:))
}
}
}
return result
}
提前致谢。