In Xcode 4, I created a new Cocoa application called Tabletest
, on xib I added an NSTableView
and dragged it into the delegate object
application (created automatically when I created the new Cocoa application). I set up the dataSource table and delegated an application delegation object named Tabletest App Delegate
.
In tabletestAppDelegate.h
and tabletestAppDelegate.m
I added (apparently) the 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 by NSMutableArray
as NSMutableArray * myArray;
Then I control - drag the table to .h
and create a property like:
@property (assign) IBOutlet NSTableView *myTable;
In the .m
file, I added an implementation of numberOfRowsInTableView
and (id)tableView...
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])) {
"NSLog shows that the array is being filled, but the information is never displayed in the table. What am I missing? I'm a complete Cocoa newbie and I have no idea why adding information to a simple table is so difficult.
Thanks for the help.
source share