So it's likely that you solved this long ago, but in case someone else stumbles across this question...
I am populating the array via NSMutableArray
, but I am not sure how can I populate the array via NSArrayController
, since I don't have the instance in my Controller.m class. Please tell me how can I resolve this issue.
It is possible that you were doing something like
[myData addObject:someObject];
However, your NSArrayController
will not learn of this change to the NSMutableArray
instance because addObject
is not KVC compliant. You need to inform any object that is observing that your NSMutableArray
instance has changed. There are at least two ways to do this. Assuming that your NSMutableArray
instance property is named "myData", then you can do something like the following:
[self.willChangeValueForKey:@"myData"];
[myData addObject:someObject];
[self.didChangeValueForKey:@"myData"];
or
NSMutableArray *bindingsCompliantArray = [self mutableArrayValueForKey:@"myData"];
[bindingsCompliantArray addObject:someObject];
Another SO answer (linked) has a good explanation on what mutableArrayValueForKey actually does, but I recommend reading the Apple developer docs on key-value coding and key-value observation to help understand it.
I have dragged the NSController instance in my mainmenu.nib tray. Do i need to declare an IBOutLet NSArrayController in my Controller.h file and then connect it with the NSArrayController instance in the tray ?
You need a NSArrayController
instance in your nib file, but you do not need an IBOutlet in your interface for the situation that you've described here. The NSArrayController
should be bound to the key of your NSMutableArray
(myData in my example) and it sounds like you already have your table columns bound correctly.