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.
Best Answer
For one thing, the data source methods now deal with
NSInteger
s, notint
s.More relevantly, if your deployment target is Mac OS X 10.6 or later, then you need to declare your data source's class as conforming to the
NSTableViewDataSource
formal protocol in your class's@interface
. (This protocol and many others are new in 10.6; previously, they were informal protocols.)