[英]No method found compiler warning
我從字符串創建一個類,檢查它是否有效,然后檢查它是否響應特定方法。 如果是,那么我調用該方法。 這一切都很好,除了我得到一個惱人的編譯器警告:“警告:沒有'-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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.