Mr Aleph Mr Aleph - 1 year ago 94
Objective-C Question

NSTAbleView is not displaying contents of the NSMutableArray

In Xcode 4 I created a new Cocoa application called

, on the xib I added a
and control-dragged it to the app's
delegate object
(created automatically when you create the new Cocoa app). I set the table's dataSource and delegate to the app's delegate object called
Tabletest App Delegate

I added the (apparently) required

- (int)numberOfRowsInTableView:(NSTableView *)tableView;
- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row;

- (int)numberOfRowsInTableView:(NSTableView *)tableView
return (int)[myArray count];

- (id)tableView:(NSTableView *)tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)row
return [myArray objectAtIndex:row];

and declared an
NSMutableArray * myArray;

Then I control-dragged the table to the
and created a property like:

@property (assign) IBOutlet NSTableView *myTable;

On the
file I added the implementation of

and added:

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
myArray = [[NSMutableArray alloc] initWithCapacity:10];
int i = 0;
for(i=0; i<10;i++)
[myArray insertObject: [NSString stringWithFormat:@"This is string %d!",i+1] atIndex:i];

NSEnumerator * enumerator = [myArray objectEnumerator];
id element;

while((element = [enumerator nextObject]))
// Do your thing with the object.
NSLog(@"%@", element);


The `NSLog show the array gets filled but the info never shows on the table. What am I missing? I am a complete newbie on Cocoa and I have no idea why adding information to a simple table is so complicated.

Thank for the help.

Answer Source

I'll answer my own question, add

[_myTable reloadData];
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download