基于视图的 NSOutlineView 中 NSTextField 的委托事件?
我有一个完美运行的基于视图的 NSOutlineView
,并在我的项目中设置了正确的数据源。现在我想允许用户更改某些条目。所以我使 IB 中的 NSTextField 可编辑。对于基于单元格的 NSOutlineView
,您可以使用委托方法 outlineView:setObjectValue:forTableColumn:byItem:
,但它不适用于基于视图的 NSOutlineView
> 如 NSOutlineViewData
协议的头文件中所述:
/* View Based OutlineView:此方法不适用。 */
(void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
所以我搜索了另一个委托方法并找到了outlineView:shouldEditTableColumn:item:。但是这个委托方法不会被触发。可能是因为我没有编辑单元格。
所以我的问题是:除了为每个 NSTextField 分配一个委托之外,还有其他方法可以注意到行的更改吗?
I have a flawless functioning view-based NSOutlineView
with a proper set-up datasource in my project. Now I want to allow the user to change certain entries. So I made the NSTextField
in the IB editable. For a cell-based NSOutlineView
you can use the delegate method outlineView:setObjectValue:forTableColumn:byItem:
however it's not available for a view-based NSOutlineView
as stated in the header file for the NSOutlineViewData
protocol:
/* View Based OutlineView: This method is not applicable.
*/(void)outlineView:(NSOutlineView *)outlineView setObjectValue:(id)object forTableColumn:(NSTableColumn *)tableColumn byItem:(id)item;
So I searched for another delegate method and found outlineView:shouldEditTableColumn:item:
. However this delegate method doesn't get fired. Probably because I'm not editing a cell.
So my question is: Is there any other way to notice when a row changed than having a delegate for each NSTextField
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的文本字段需要在 Interface Builder 中可编辑是正确的。
接下来,使您的控制器符合 NSTextFieldDelegate。然后,在outlineView:viewForTableColumn:item: 中设置文本字段的委托,如下所示:
这是一个简化的示例,您已在其中实现了为大纲视图的项目返回表格单元格视图的方法。
然后,控制器应该收到 controlTextDidEndEditing 通知:
You are correct that your text field needs to be editable in Interface Builder.
Next, make your controller conform to NSTextFieldDelegate. Then, set the delegate for the text field in outlineView:viewForTableColumn:item:, like so:
Here's a simplified example, where you've implemented the method for returning the table cell view for an item for your outline view.
Then, the controller should get a controlTextDidEndEditing notification:
好吧,苹果似乎希望我们使用每个
NSTextField
的委托方法,如 此处:所以目前没有其他方法可以做到这一点。
Well, it seems like Apple wants us to use the delegate methods of each
NSTextField
as stated here:So there's currently no other way to do this.