NSArrayController not working with NSMutableDictionary for NSTableView

Discussion in 'Mac Programming' started by Monaj, May 11, 2010.

  1. Monaj macrumors regular

    Joined:
    May 24, 2009
    #1
    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 : http://www.4shared.com/file/f9fW1klP/TableControllerHunt-1.html.

    Can anyone suggest me where I may be wrong?

    Thanks,

    Monaj
     
  2. kainjow Moderator emeritus

    kainjow

    Joined:
    Jun 15, 2000
    #2
    When you modify your array directly the array controller doesn't know that you did, so it doesn't update. In order to update the array you can access it through Key-Value Coding:
    Code:
    [[self mutableArrayValueForKey:@"geniuses"] addObject:genius1];
    
    However I would not recommend this for the initial setup of your array. Instead you can use @properties and assign your array to a temporary array.
     

Share This Page