views:

179

answers:

2

Hi all,

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

  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.

You can find my code here.

Can anyone suggest me where I may be wrong?

Thanks,

Miraaj

+1  A: 

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.

Preston
Not just implement them, but use them. That is, you must send yourself accessor messages, not mutate the array directly.
Peter Hosey
I thought that was implied, but you're right that I should have been clearer, so I edited my post.
Preston
+1  A: 

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.

Peter Hosey