在NSTableView上结束编辑(基于视图) [英] End Editing on NSTableView (View Based)

查看:78
本文介绍了在NSTableView上结束编辑(基于视图)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户正在编辑表视图中的文本字段并决定单击该窗口的关闭按钮时,不会保存他/她所做的更改.如何强制表格视图(基于视图)结束编辑(而不是中止编辑)?

解决方案

最简单的方法是为您的窗口分配一个委托并响应 NSWindow 解决方案

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆