直到它失去焦点绑定的NSTextField不更新实体 [英] Binded NSTextField doesn't update the entity until it lose the focus

查看:219
本文介绍了直到它失去焦点绑定的NSTextField不更新实体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个核心数据项目。

I have a Core Data project.

基本上我有一个NSTableView的,我加了一些实体(使用补充说:选择器),在TableView中双击打开一个新NSWindow,其中可以编辑使用一些NSTextFields的实体。
每个文本字段被绑定到实体的属性。

Basically I have an NSTableView where I add some entities (using the "add:" selector), double clicking on the TableView opens a new NSWindow where is possible to edit the entity using some NSTextFields. Each text field is binded to an attribute of the entity.

一切工作正常,但事实上,当一个文本框失去焦点的实体的属性才会更新。

Everything is working fine, except the fact that the entity's attributes are updated only when a textfield lose the focus.

如果我写的第一个文本字段,然后我移动到第二个我的条目保存,但如果我写的第一个文本字段,并在我结束我失去了我的变化窗口。

If I write on the first text field and then I move to the second one my entry is saved, but if I write on the first text field and I close the window I lose my changes.

我怎样才能尽快更新我的核心数据实体,因为我写在文本字段的东西吗?我应该使用 textDidChange:

How can I update my core data entity as soon as I write something in the text field? Should I use textDidChange:?

--- ---更新

不幸的是[背景下保存]不起作用。如果我理解正确的实体的不可以修改,直到辞职的NSTextField第一响应者。

Unfortunately [context save] doesn't work. If I understand correctly the entity is not modified until the NSTextField resign first responder.

现在唯一的工作液是一样的东西:

The only working solution for now is something like:

(void)controlTextDidChange:(NSNotification *)aNotification 
{
  NSTextField *tf = [aNotification object];
  [self.window makeFirstResponder:tf];
}

不过这是相当不雅,在任何情况下,我也还是需要重新设置光标在的NSTextField的结尾。

but this is quite inelegant, and in any case I also still need to re-set the cursor at the end of the NSTextField.

推荐答案

设置 NSContinuouslyUpdatesValueBindingOption 将导致模型更新每次文本字段的变化,这台脏标志正确并导致文档保存退出。

Setting NSContinuouslyUpdatesValueBindingOption will cause the model to update every time the text field changes, which sets the dirty flag properly and causes the document to save on quit.

这篇关于直到它失去焦点绑定的NSTextField不更新实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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