在NSTableView上结束编辑(基于视图) [英] End Editing on NSTableView (View Based)
问题描述
当用户正在编辑表视图中的文本字段并决定单击该窗口的关闭按钮时,不会保存他/她所做的更改.如何强制表格视图(基于视图)结束编辑(而不是中止编辑)?
最简单的方法是为您的窗口分配一个委托并响应 NSWindow
的 -makeFirstResponder:使窗口本身成为第一响应者,并注意它给出的 BOOL
答案.您应该返回任何 -makeFirstResponder:
答案作为委托 ... ShouldClose:
消息的答案,因为它可能无法结束编辑/退出第一响应者.假设成功,它将结束编辑并触发您在实际关闭之前设置的任何操作/绑定机制.之所以可行,是因为 NSTableView
及其在基于视图的模式下使用的视图是 NSControl
的子类,并通过结束编辑等方式自动处理响应者的状态更改.希望这对您有所帮助./p>
When a user is mid-editing a textfield on a tableview and decides to click the close button for the window, the changes he/she made does not get saved. How can I force a tableview (view based) to end editing (not abort editing) ?
The simplest way to do this is to assign a delegate for your window and respond to NSWindow
's -windowShouldClose: delegate method. In it, invoke -makeFirstResponder: to make the window itself the first responder, noting the BOOL
answer it gives. You should return whatever -makeFirstResponder:
answers as the answer to the delegate ...ShouldClose:
message since it may not be able to end editing / resign first responder. Assuming it's successful, it'll end editing and trigger whatever action / bindings machinery you set up prior to actually closing. This works because NSTableView
and the views it uses in view-based mode are subclasses of NSControl
and automatically handles the responder status changes by ending editing, etc. Hope this helps.
这篇关于在NSTableView上结束编辑(基于视图)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!