Reputation: 1139
I am new to Cocoa . I am displaying a simple Tableview populated with NSMutableArray which is bound to the NSArrayController as follows
[_arrController bind:@"contentArray" toObject:self withKeyPath:@"dataArray" options:nil];
Here _arrController is the IBoutlet to my NSArrayController and dataArray is my NSmutableArray with the data.
I am successful in populating the Tableview when I do the binding programatically. However I am not able to achieve the same binding through the Interface Builder.
I selected ArrayController in my IB , went to binding section,and tried binding under the controller section by selecting the model key path as dataArray.But however , my table is not populated with data , where as programatically I can achieve my task easily. Any help is appreciated.
Upvotes: 3
Views: 5275
Reputation: 587
Here is a example which might help you to fix the issue.
@interface ExAppDelegate : NSObject
@property (assign) IBOutlet NSWindow *window;
@property (strong) NSMutableArray *demoArray;
@property (strong) IBOutlet NSArrayController *demoArrayController;
@end
Below is the implementation of the same class
@implementation ExAppDelegate
@synthesize demoArray;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
// Insert code here to initialize your application
self.demoArray = [NSMutableArray array];
for (int i=0 ; i <= 10 ; i++)
{
NSMutableDictionary *temp = [NSMutableDictionary dictionary];
[temp setObject:[NSNumber numberWithInt:i] forKey:@"number"];
[temp setObject:[NSString stringWithFormat:@"Demo %d",i] forKey:@"demoKey"];
[self.demoArray addObject:temp];
}
[self.demoArrayController rearrangeObjects];
}
@end
Now, UI Bindings - >
NOTE:
1. Make sure you are calling the rearrangeObjects on Array Controller after you add the objects to an array which is binded to Array Controller.
[self.demoArrayController rearrangeObjects];
2. In Table View Column Bindings make sure you have checked the check box "Continuously Updates Value".
I Hope this fix the issue.
Upvotes: 7
Reputation: 3612
The steps are as follows (just in case you missed anything):
If you are using and View based table view. Do following:
Hope it helps!
Upvotes: 1