可可:在控件绑定避免'不断更新“ [英] Cocoa: Avoiding 'Updates Continuously' in control binds

查看:133
本文介绍了可可:在控件绑定避免'不断更新“的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有包含的文件的所有者的对象中必然属性的NSTextField 控制面板数。如果用户编辑字段,然后presses的标签的,移动到下一个字段,它按预期工作。但是,如果用户没有preSS的标签的,只是presses OK按钮,新的值不会在文件的所有者的对象设置。

I have several panels that contain NSTextField controls bound to properties within the File's Owner object. If the user edits a field and then presses Tab, to move to the next field, it works as expected. However if the user doesn't press Tab and just presses the OK button, the new value is not set in the File's Owner object.

为了解决这个我已经设置的更新不断在绑定的,但是这一定是贵(编辑:或者至少是不雅)。

In order to workaround this I have set Updates Continuously in the binding, but this must be expensive ( or at least it's inelegant).

有没有办法强制绑定更新时确定按钮是pssed,而不是使用$ P $的更新不断的?

Is there a way to force the bind update when the OK button is pressed rather than using Updates Continuously?

推荐答案

您说得对,你不需要使用不断更新的价值选择。

You're right that you don't need to use the continuously updates value option.

如果你使用绑定(你是),那么你应该做的是调用 NSController <的 -commitEditing 方法/ code>子类,它的管理的结合。你通常会做这在你的方法关闭,你显示表。

If you're using bindings (which you are), then what you should be doing is calling the -commitEditing method of the NSController subclass that's managing the binding. You'd normally do this in your method that closes the sheet that you're displaying.

-commitEditing 告诉控制器来完成在主动控制的编辑和提交当前编辑绑定的对象。

-commitEditing tells the controller to finish editing in the active control and commit the current edits to the bound object.

这是一个好主意,把这个当你执行的是持久性的操作,如保存。

It's a good idea to call this whenever you are performing a persistence operation such as a save.

这篇关于可可:在控件绑定避免'不断更新“的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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