我从字符串创建一个类,检查它是否有效,然后检查它是否响应特定方法。如果是,那么我调用该方法。一切正常,除了我收到一个烦人的编译器警告:“警告:未找到 '-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];
干杯
戴夫
最佳答案
要么导入声明该方法的 header ,要么在您的实现中使用非正式协议(protocol)来声明它。编译器必须知道方法的签名。
@interface NSObject (MyInformalProtocol)
- (void)setCurrentID:(int)id;
@end
关于iphone - 找不到方法编译器警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2895888/