我从字符串创建一个类,检查它是否有效,然后检查它是否响应特定方法.如果是,那么我调用该方法.这一切都很好,除了我得到一个恼人的编译器警告:“警告:没有’-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];
干杯
戴夫
解决方法
导入声明方法的标头,或者只是在实现中使用非正式协议来声明它.编译器必须知道方法的签名.
@interface NSObject (MyInformalProtocol) - (void)setCurrentID:(int)id; @end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。