Search code examples
objective-cxcodecocoansmutablearraynsarraycontroller

arraycontroller nsmutablearray add programmatically


I trying to add a data on table view via Array Controller thats bind to a NSMutableArray. On the IB property it looks like this :

IB Property File's owner

and on the code I tried to add the NSMutableArray dynamically then reload the view, bu nothings happened.

for(int i=0;i<10;i++){
        NSMutableDictionary *group = [[NSMutableDictionary alloc]init];
        [group setValue:[NSString stringWithFormat:@"%@-%d", @"Group", i] forKey:@"groupname"];
        [contentArray addObject:group];
    }
    [tableContent reloadData];

I have been google it and browse the same question in stackoverflow, not found a useful one.

any idea ?

Thanks

updated

I wrote above code in File's owner class.


Solution

  • I think the problem is that the array needs to send a KVO notification to the array controller (or maybe it's the table view, I'm not sure). The way to do that is:

    self.contentArray = contentArray; (or _contentArray if that's what your ivar is called). I'm assuming that contentArray is a property, if not, you should make it one.