문제

나는 목표 c/coaoa를 학습하려고 노력하고 있지만, 나는 nstableview 객체를 나를 위해 일하는 데 약간 고착 된 것 같습니다. 나는 모든 방향을 따랐지만 어떤 이유로 든 여전히이 오류가 발생합니다.

Class 'RobotManager' does not implement the 'NSTableViewDataSource' protocol

여기 내 출처가 있습니다. 여기에서 틀린 것이 무엇인지 말 해주세요. 나는 내 얼굴을 찢어 버릴 것입니다.

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

그것이 차이가 있다면 OS X 10.6.1을 실행하고 있습니다. 미리 감사드립니다.

도움이 되었습니까?

해결책

선언을 변경해보십시오 @interface 다음에 :

@interface RobotManager : NSObject <NSTableViewDataSource> {

이것은 컴파일러에게 RobotManager 수업은 다음과 같습니다 NSTableViewDataSource 규약.

편집하다:

또한 아마도 그럴 것입니다 RobotList 두 가지 방법 전에 초기화되지 않습니다 NSTableViewDataSource 부름을 받고 있습니다. 다시 말해, awakeFromNib 호출되지 않습니다.

명백한 전화가 없다면 awakeFromNib 일부 발신자로부터 RobotList 초기화되지 않으므로 채우지 않고 RobotList 그 방법에서, 그것을 채우십시오 RobotManager 처음으로 인스턴스화됩니다.

다른 팁

우선, 데이터 소스 방법은 이제 NSIntegerS, 그렇지 않습니다 int에스.

보다 관련 적으로 배포 대상이 Mac OS X 10.6 이상인 경우 데이터 소스의 클래스를 준수하는 것으로 선언해야합니다. 그만큼 NSTableViewDataSource 공식적인 규약 당신의 수업에서 @interface. (이 프로토콜과 다른 많은 프로토콜은 10.6에서 새롭습니다. 이전에는 비공식 프로토콜이었습니다.)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top