gpt4 book ai didi

cocoa - 使用 setValue :forKey: against it's CoreData bound field 时 NSPopupButton 不更新

转载 作者:行者123 更新时间:2023-12-03 17:22:00 25 4
gpt4 key购买 nike

我正在开发一个基于 CoreData/Document 的应用程序。在用户界面的一个区域中,我设置了一个包含各种列的 View 模式表。一列中有一个 NSPopupButton,其选定索引绑定(bind)设置为 Table Cell View.objectValue.startupState。

选择弹出窗口中的任何菜单项都会使用单击的菜单项的索引正确更新实体上的startupState属性,并且NSPopupButton文本也会更新。我已经验证属性值实际上是通过保存、关闭和重新打开文档来更新的。

在另一列中,我有一个 NSPopupButton 与同一实体中的另一个属性类似地绑定(bind) - Table Cell View.objectValue.mode。根据模式选择,它将通过手动实现 setMode 来修改startupState值,setMode在某些情况下会执行此语句:

[self setValue:[[NSNumber alloc] initWithInt:1] forKey:@"startupState"];

我遇到的问题是 NSPopupButton 没有更新以显示所选索引的菜单项文本。和以前一样,在运行上述代码并选择正确的项目/出现文本后,我保存、关闭并重新打开文档,因此我知道 setValue 调用更新了属性。

有什么想法吗?

最佳答案

正如评论中提到的,沃尔克的建议解决了这个问题。 setValue:forKey 调用周围需要 willChangeValueForKey 和 didChangeValueForKey 消息,如下所示:

    [self willChangeValueForKey:@"startupState"];
[self setValue:[[NSNumber alloc] initWithInt:1] forKey:@"startupState"];
[self didChangeValueForKey:@"startupState"];

关于cocoa - 使用 setValue :forKey: against it's CoreData bound field 时 NSPopupButton 不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21619259/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com