End Editing on NSTableView (View Based)

拥有回忆 提交于 2021-02-04 16:12:06

问题


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) ?


回答1:


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.



来源:https://stackoverflow.com/questions/22383709/end-editing-on-nstableview-view-based

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!