简体   繁体   English

处理编辑 NSTableView

[英]Handling editing an NSTableView

I have an NSTableView backed by an NSArrayController subclass.我有一个由 NSArrayController 子类支持的 NSTableView。 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.我想在表中添加一个新行,所以我为 addObject 创建了一个覆盖来处理我的自定义 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.调用时, addObject 将新的 object 插入到底层数组中,但新行是表中的最后一行,(我认为这是有道理的,因为它添加到底层数组的末尾),但我想要新行作为第一行插入。 So I changed my addObject to insert the new item at index 0 (insertObject:atArrangedObjectsIndex:).所以我更改了我的 addObject 以在索引 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).现在,新行作为第一行插入,第 0 列中的单元格是可编辑的(是的。),但是,当我跳到下一个单元格时(在第 1 列,第 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.在我在可编辑字段中输入一个值后,排序开始了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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