obj-c,混乱为什么我不能在这个类中添加一个setter?

Jul*_*les 0 xcode objective-c

通常我在向类添加setter方法时没有任何问题.

但是,我正在尝试添加到库使用类,这必然会导致问题.

继承我上课的课程......

@interface GraphController : TKGraphController {
UIActivityIndicatorView *indicator;
NSMutableArray *data; //I've added
NSString *strChartType; //I've added
}
-(void)setContentType:(NSString*)value; //I've added
@end

@implementation GraphController
-(void)setContentType:(NSString*)value { //I've added

if (value != strChartType) {
    [value retain];
    [strChartType release];
    strChartType = value;
    NSLog(@"ChartType=%@", strChartType);
}     
}
Run Code Online (Sandbox Code Playgroud)

在我收到警告的地方

UIViewController *vc = [[GraphController alloc] init];      
[vc setContentType:myGraphType];  //Warnings on this line see below
[self presentModalViewController:vc animated:NO];
[vc release];
Run Code Online (Sandbox Code Playgroud)

myGraphType如果在我的常量类中定义.

*警告*

warning: 'UIViewController' may not respond to '-setContentType:'
warning: (Messages without a matching method signature
Run Code Online (Sandbox Code Playgroud)

我知道当你没有将方法添加到实现时,会出现第一个警告.但是我有.

我哪里错了?

小智 5

UIViewController *vc = [[GraphController alloc] init];
Run Code Online (Sandbox Code Playgroud)

表示vc指向一个实例,GraphController但该变量本身属于类型UIViewController *,并且UIViewController不声明-setContentType:方法.

替换为

GraphController *vc = [[GraphController alloc] init];
Run Code Online (Sandbox Code Playgroud)

告诉编译器你正在使用一个GraphController实例,它会识别你的-setContentType:方法.