简体   繁体   English

在 NSTableView 上结束编辑(基于视图)

[英]End Editing on NSTableView (View Based)

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.当用户在 tableview 上编辑文本字段并决定单击窗口的关闭按钮时,他/她所做的更改不会被保存。 How can I force a tableview (view based) to end editing (not abort editing) ?如何强制 tableview(基于视图)结束编辑(而不是中止编辑)?

The simplest way to do this is to assign a delegate for your window and respond to NSWindow 's -windowShouldClose: delegate method.最简单的方法是为您的窗口分配一个委托并响应NSWindow-windowShouldClose:委托方法。 In it, invoke -makeFirstResponder: to make the window itself the first responder, noting the BOOL answer it gives.在其中,调用-makeFirstResponder:使窗口本身成为第一响应者,注意它给出的BOOL答案。 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.您应该返回任何-makeFirstResponder: answers 作为对委托的回答...ShouldClose:消息,因为它可能无法结束编辑/退出第一响应者。 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和它在基于视图的模式下使用的视图是NSControl子类,并通过结束编辑等自动处理响应者状态更改。希望这会有所帮助。

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

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