简体   繁体   中英

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. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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