简体   繁体   中英

How do I get the “item” or the row index of an edited NSOutlineView text field cell?

I'm using NSOutlineView with a Text Field / Text Field Cell as show in the images below:

在此处输入图片说明

在此处输入图片说明

The code for the sent action function:

@IBAction func handleTextFieldDidEndEditing(_ sender: Any) {
    print("LeftNavBarOutlineView selectedRow: \(self.selectedRow)")
    print("LeftNavBarOutlineView editedRow: \(self.editedRow)")
    print("LeftNavBarOutlineView selectedRowIndexes.count: \(self.selectedRowIndexes.count)")

    let taskName = (sender as! NSTextField).stringValue
    print("LeftNavBarOutlineView " + taskName)
}

The printout result:

LeftNavBarOutlineView selectedRow: -1
LeftNavBarOutlineView editedRow: -1
LeftNavBarOutlineView selectedRowIndexes.count: 0
LeftNavBarOutlineView

The problem:

"sender" object is an NSTextField instance. I need to retrieve the "item" as returned by my func outlineView(_ outlineView: NSOutlineView, child index: Int, ofItem item: Any?) -> Any function.

I either need to get the "item" directly, or the row index (which I can retrieve the "item" from my map-dictionary)

Since the "sender" is an NSTextField, how can I find out what is the row (or "item") which has just been edited?

Thanks!

Get the row with row(for view and the item with item(atRow

@IBAction func handleTextFieldDidEndEditing(_ sender: NSTextField) {
    let row = outlineView.row(for: sender)
    let item = outlineView.item(atRow: row)

outlineView is the NSOutlineView instance

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM