iphone – 找不到编译器警告的方法

前端之家收集整理的这篇文章主要介绍了iphone – 找不到编译器警告的方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我从字符串创建一个类,检查它是否有效,然后检查它是否响应特定方法.如果是,那么我调用方法.这一切都很好,除了我得到一个恼人的编译器警告:“警告:没有’-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

猜你在找的Xcode相关文章