简体   繁体   中英

Handling editing an NSTableView

I have an NSTableView backed by an NSArrayController subclass. The data displays correctly in the table when the app loads, so all is good there. I want to add a new row to the table, so I created an override for addObject to handle my custom object. When called, addObject inserts the new object into the underlying array, but the new row is the last row in the table, (makes sense, I think, as its added to the end of the underlying array), but I want the new row to be inserted as the first row. So I changed my addObject to insert the new item at index 0 (insertObject:atArrangedObjectsIndex:). Now the new row is inserted as the first row and the cell in column 0 is editable (Yeah.), BUT, when I tab to the next cell (in column 1, row 0). the selection jumps to the last row in the table and makes the cell in the second column editable. Not what I want? So how do add a new first row to my table? Make it editable without the selection switching to the last row?

I found the problem. I was programmatically sorting the table as items were added. The sort kicked in after I entered a value in the editable filed.

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