0

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.

Alfian Busyro
  • 2,295
  • 2
  • 17
  • 32

1 Answers1

0

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.

rdelmar
  • 103,982
  • 12
  • 207
  • 218
  • thanks for your answer. hmm... actually I already put my contentArray as a property. – Alfian Busyro Aug 14 '12 at 04:44
  • @arufian yes, but did you add the line I put in my answer? – rdelmar Aug 14 '12 at 04:50
  • yes I put that one, nothings happened. btw, can I ask one simple question(it's not related though). Is it possible to build nstableview with view based for Snow Leopard ? – Alfian Busyro Aug 14 '12 at 04:56
  • I don't remember whether you can do that on Snow Leopard. Are you using a view based table? If so what are the columns bound to? It should be working, there must still be something wrong with the bindings. – rdelmar Aug 14 '12 at 05:09
  • yes I using view based table, I only have one column that contain Text Table Cell View (thats created on IB), then I bound the textfield to a key of contentArray. – Alfian Busyro Aug 14 '12 at 06:19
  • 1
    I don't think that's right. The table view's content binding should be bound to the array controller arrangedObjects. The textField should be bound to Table Cell View with a model key path of objectValue.groupName This is all described in the Table View Programming Guide in the "Creating the Bindings for a View-Based Table View" section – rdelmar Aug 14 '12 at 06:45
  • I see. But unfortunately, I have to implementing cell-based table view instead of view-based table view, because of the requirement. I'll accept this as the right answer. – Alfian Busyro Aug 14 '12 at 10:39