Problems with NSTableView

I am working on learning Objective-C / Coaoa, but it seems like I got a bit stuck on getting the NSTableView object working for me. I followed all 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 wrong here, I'm about to rip 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 am running OS X 10.6.1 if that matters. Thanks in advance.

+2


source to share


2 answers


Try changing your ad @interface

to the following:

@interface RobotManager : NSObject <NSTableViewDataSource> {

      

This will tell the compiler that the class is RobotManager

following the protocol NSTableViewDataSource

.



Edit:

Also, it is probably RobotList

not initialized until the two methods are NSTableViewDataSource

called. In other words, awakeFromNib

it is not called.

If there is no explicit call awakeFromNib

from some caller, RobotList

it will not initialize, so instead of filling RobotList

in this method, try filling it when RobotManager

first instantiated.

+6


source


On the one hand, data source methods now deal with NSInteger

s rather than int

s.



Moreover, if the deployment target is Mac OS X 10.6 or later, then you need to declare your data source class as a formal NSTableViewDataSource

protocol
in your class @interface

. (This protocol and many others are new in 10.6; they were previously unofficial protocols.)

+8


source







All Articles