找不到编译器警告的方法

时间:2010-05-24 09:15:52

标签: iphone objective-c xcode compiler-warnings

我从字符串创建一个类,检查它是否有效,然后检查它是否响应特定方法。如果是,那么我调用该方法。这一切都很好,除了我得到一个恼人的编译器警告:“警告:没有'-setCurrentID:'方法找到”。我在这里做错了吗?有没有告诉编译器一切正常并停止报告警告?

这是代码:

// Create an instance of the class
id viewController = [[NSClassFromString(class) alloc] init];

// Check the class supports the methods to set the row and section
if ([viewController respondsToSelector:@selector(setCurrentID:)]) 
    {
        [viewController setCurrentID:itemID];
    }   

// Push the view controller onto the tab bar stack      
[self.navigationController pushViewController:viewController animated:YES];
[viewController release];

干杯

戴夫

1 个答案:

答案 0 :(得分:7)

导入声明方法的标头,或者只是在实现中使用非正式协议来声明它。编译器必须知道方法的签名。

@interface NSObject (MyInformalProtocol)

- (void)setCurrentID:(int)id;

@end
相关问题