NSArrayController 无法与 NSTableView 的 NSMutableDictionary 一起使用
我正在尝试使用 NSMutableDictionary 记录的 NSMutableArrayController 在 NSTableView 中显示内容。
我按照下面写的步骤操作:
在应用程序委托类中,我创建了一个名为“geniuses”的 NSMutableArray 对象,并存储了一些带有键的 NSMutableDictionary 对象:“geniusName”和“domain”。
我在 IB 中获取了一个 NSArrayController 对象,将其控制器内容属性绑定到应用程序委托类,并将其模型键路径设置为“geniuses”。在属性检查器窗格中将模式设置为类,并将类名称设置为 NSMutableDictionary。额外 键:“geniusName”和“domain”。
在 IB 中,我采用了一个表视图对象。将其内容属性绑定到数组控制器,控制器键路径设置为排列对象。将其第一列的 value 属性绑定到数组控制器,控制器键路径设置为排列对象,模型键路径设置为“geniusName”。将其第二列的 value 属性绑定到数组控制器,控制器键路径设置为排列对象,模型键路径设置为“geniusName”。
遵循这些步骤后,当我尝试构建和运行项目时,我发现未填充的表视图。
谁能建议我哪里可能错了?
谢谢,
米拉杰
I am trying to display content in NSTableView using NSMutableArrayController of NSMutableDictionary records.
I followed steps written below:
In application delegate class, I created an NSMutableArray object with name 'geniuses' and stored some NSMutableDictionary objects with keys: 'geniusName' and 'domain'.
I took an NSArrayController object in IB, binded its controller content property to application delegate class, and set its model key path to 'geniuses'. In attribute inspector pane set mode as class and class name as NSMutableDictionary. Added
keys: 'geniusName' and 'domain' to it.In IB I took a table view object. Binded its content property to array controller, controller key path set as arranged objects. Binded value property of its first column to array controller, controller key path set as arranged objects, model key path set as 'geniusName'. Binded value property of its second column to array controller, controller key path set as arranged objects, model key path set as 'geniusName'.
After following these steps when I tried to build and run the project I found un-populated table view.
Can anyone suggest me where I may be wrong?
Thanks,
Miraaj
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我现在无法检查您的代码。您如何填充 geniuses 数组?您必须实现 键值编码访问器方法,并在从数组插入或删除数据时使用这些方法以生成 KVO 通知。
I can't check your code right now. How are you populating the genuises array? You must implement key-value-coding accessor methods and use those when inserting or removing data from an array in order to generate KVO notifications.
我假设您有一个为可变数组声明的实例变量:
但是您实际上创建了该数组吗?
该变量只是指向数组对象的指针的容器。您仍然需要创建一个数组对象并将其指针放入变量中,可能在应用程序委托的
init
或initWithCoder:
方法中。忘记这样做是您所看到的问题的常见原因。在创建数组之前,实例变量包含
nil
,所有将内容放入不存在的数组或从不存在的数组中检索内容的尝试都是发送给nil
的消息,这不会执行任何操作。I assume you have an instance variable declared for the mutable array:
But did you actually create the array?
The variable is merely a container for the pointer to an array object. You still need to create an array object and put its pointer in the variable, probably in your application delegate's
init
orinitWithCoder:
method.Forgetting to do that is a common cause of the problem you're seeing. Until you create the array, the instance variable contains
nil
, and all attempts to put things into or retrieve things from the non-existent array are messages tonil
, which do nothing.