Cocoa - 尝试写入时绑定数组为空
我正在 XCode 中编写一个主从程序,并且想要添加保存用户输入的所有数据的功能。目前我有一个 assignmentArray
(NSMutableArray
)在绑定到 NSArrayController 的控制器对象中。单击按钮时,它应该将我的模型对象的实例添加到数组中。这看起来效果很好。但是,当我尝试保存它时,数组是空的。据我从调试中看到,数组始终为空。为什么它不包含这些对象? 我按照此教程进行操作,我的代码没有任何错误或警告。
I am writing a Master-Detail program in XCode, and want to add the ability to save all the data the user has put in. Currently I have an assignmentArray
(NSMutableArray
) in my controller object that is bound to an NSArrayController
. When clicking a button, it should add an instance of my model object to the array. This appears to work fine. However, when I try to save it, the array is empty. As far as I have seen from debugging, the array is always empty. Why is it not containing these objects?
I followed this tutorial and my code doesn't have any errors or warnings.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题是我将 ArrayController 绑定到模型对象而不是文件的所有者。改变这个解决了问题。
The problem was that I bound the ArrayController to the model object instead of File's Owner. Changing this fixed the problem.
确保您已将 ArrayController 绑定到
File's Owner
而不是控制器的实例!Make sure you have bound your ArrayController to
File's Owner
and not an instant of your controller!