I’m working on learning Objective-C/Coaoa, but I’ve seem to have gotten a bit stuck with getting the NSTableView object to work for me. I’ve followed all the directions, but for some reason I still get this error:
Class 'RobotManager' does not implement the 'NSTableViewDataSource' protocol
Here’s my source, tell me what you see is wrong here, I’m about to tear my face off.
RobotManager.h
@interface RobotManager : NSObject {
// Interface vars
IBOutlet NSWindow *MainWindow;
IBOutlet NSTableView *RobotTable;
NSMutableArray *RobotList;
}
- (int) numberOfRowsInTableView: (NSTableView*) tableView;
- (id) tableView:(NSTableView *) tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex;
@end
RobotManager.m
#import "RobotManager.h"
@implementation RobotManager
-(void) awakeFromNib {
// Generate some dummy vals
[RobotList addObject:@"Hello"];
[RobotList addObject:@"World"];
[RobotTable setDataSource:self]; // This is where I'm getting the protocol warning
[RobotTable reloadData];
}
-(int) numberOfRowsInTableView: (NSTableView *) tableView {
return [RobotList count];
}
-(id) tableView:(NSTableView *) tableView objectValueForTableColumn:(NSTableColumn *)tableColumn row:(int)rowIndex {
return [RobotList objectAtIndex:rowIndex];
}
@end
I’m running OS X 10.6.1 if that makes any difference. Thanks in advance.
Try changing the declaration of the
@interfaceto the following:This will tell the compiler that the
RobotManagerclass follows theNSTableViewDataSourceprotocol.Edit:
In addition, it’s probably likely that the
RobotListis not being initialized before the two methods ofNSTableViewDataSourceare being called. In otherwords,awakeFromNibis not being called.Unless there is an explicit call to the
awakeFromNibfrom some caller, theRobotListwon’t be initialized, so rather than populating theRobotListin that method, try populating it when theRobotManageris first instantiated.