I’m trying to use NSTableView (it’s my first attempt at it) but it’s showing nothing.
I created a project (ARC), i have a tableview in my xib, i dragged the “Data Source” and “Delegate” to my AppDelegate Object.
I have the following code on AppDelegate.h :
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate, NSTableViewDelegate, NSTableViewDataSource>{
NSMutableArray* array;
}
@property (assign) IBOutlet NSWindow *window;
@property (assign) IBOutlet NSTableView *tableView;
@end
And .m :
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize window = _window;
@synthesize tableView = _tableView;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
[array addObject:@"1"];
[array addObject:@"2"];
[array addObject:@"3"];
[array addObject:@"4"];
[_tableView reloadData];
}
- (id)tableView:(NSTableView *) aTableView objectValueForTableColumn:(NSTableColumn *) aTableColumn row:(NSInteger) rowIndex{
return [array objectAtIndex:rowIndex];
}
- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView{
return [array count];
}
@end
What could be the error? Thank you
Assuming the code you’ve posted is complete, the problem seems to be that you never initialize the
arrayinstance variable. Add the following line to the top of-applicationDidFinishLaunching::