Cocoa:从磁盘取消归档数据后刷新 NSObjectController
我有一个使用 NSObjectController 绑定到用户界面的对象。我能够存档该对象并稍后取消存档。到目前为止效果很好。在调试器中,我可以看到该对象保存了我在上一个会话中保存的数据。剩下的问题是:用户界面不刷新。我想我必须以某种方式告诉 NSObjectController 他必须处理另一个对象。但我不知道怎么办。我尝试了 newObject 但根本不起作用。
目前我的代码如下所示:
if ([aOpenPanel runModal] == NSOKButton)
{
NSString *filename = [aOpenPanel filename];
rpgCharacter = [NSKeyedUnarchiver unarchiveObjectWithFile:filename];
// [myCharacterController DoSomething] ???
}
rpgCharacter 应该是 myCharacterController 的对象。
I have an Object bound to the user interface with a NSObjectController. I am able to archive the Object and unarchive it later. This works fine so far. In the Debugger I can see the object holds the data I saved in a previous session. The remaining problem is: The user interface does not refresh. I guess I have to tell the NSObjectController somehow he has to deal with an other object. But I don't know how. I tried newObject but that did not work at all.
At the moment my code looks like this:
if ([aOpenPanel runModal] == NSOKButton)
{
NSString *filename = [aOpenPanel filename];
rpgCharacter = [NSKeyedUnarchiver unarchiveObjectWithFile:filename];
// [myCharacterController DoSomething] ???
}
rpgCharacter should be the object for the myCharacterController.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您正在做的是直接设置 rpgCharacter iVar。为了触发 KVO,您需要以不同的方式执行此操作:
如果您使用的是 Objective-C 2.0 和属性语法:
或者,如果您直接使用 KVC 并且有一个正确命名的 setter:
What you are doing is setting the rpgCharacter iVar directly. In order to trigger KVO you need to do this in a different way either:
if you are using Objective-C 2.0 and property syntax:
or, if you are using KVC directly and have a correctly named setter: