Question

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.

Was it helpful?

Solution

Try changing the declaration of the @interface to the following:

@interface RobotManager : NSObject <NSTableViewDataSource> {

This will tell the compiler that the RobotManager class follows the NSTableViewDataSource protocol.

Edit:

In addition, it's probably likely that the RobotList is not being initialized before the two methods of NSTableViewDataSource are being called. In otherwords, awakeFromNib is not being called.

Unless there is an explicit call to the awakeFromNib from some caller, the RobotList won't be initialized, so rather than populating the RobotList in that method, try populating it when the RobotManager is first instantiated.

OTHER TIPS

For one thing, the data source methods now deal with NSIntegers, not ints.

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.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top