开发者

NSArrayController not working with NSMutableDictionary for NSTableView

开发者 https://www.devze.com 2022-12-30 09:42 出处:网络
I am trying to display content in NSTableView using NSMutableArrayController of NSMutableDictionary records.

I am trying to display content in NSTableView using NSMutableArrayController of NSMutableDictionary records.

I followed steps written below:

  1. In application delegate class, I created an NSMutableArray object with name 'geniuses' and stored some NSMutableDictionary objects with keys: 'geniusName' and 'domain'.开发者_StackOverflow社区

  2. 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.

  3. 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


I assume you have an instance variable declared for the mutable array:

NSMutableArray *myObjects;

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 or initWithCoder: 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 to nil, which do nothing.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消