3
我从字符串创建一个类,检查它是否有效,然后检查它是否响应某个特定的方法。如果是的话,我打电话给方法。这一切工作正常,除了我得到一个恼人的编译器警告:“警告:没有'-setCurrentID:'找到方法”。我在这里做错了什么?无论如何要告诉编译器一切正常,并停止报告警告?No method found compiler warning
在这里是代码:
// 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];
干杯
戴夫
谢谢尼古拉,非常有帮助。干杯 戴夫 – 2010-05-24 11:17:16
正式和非正式协议之间的差异,这是一个很好的参考,再次感谢您的转向。 http://developer.apple.com/mac/library/documentation/cocoa/conceptual/objectivec/articles/ocProtocols.html 关心戴夫 – 2010-05-24 15:30:16
还有另一种方法来解决警告,我有时使用时,我是懒惰:NSObject的'performSelector:withObject:'而不是直接发送消息。但是,只有当你的论点是一个对象时,这才是好事。 – 2010-05-24 15:48:38