xcode 未找到实例方法(返回类型默认为 id)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13154206/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Instance method not found (return type defaults to id)
提问by cateof
I am taking a warning from Xcode. Here is the code
我正在接受 Xcode 的警告。这是代码
DeviceList *dList = (DeviceList* )[[User thisUser] devices];
[dList getListId];
The warning states that instance method -getListId is not found. However the method exists in my source code
警告指出未找到实例方法 -getListId。但是该方法存在于我的源代码中
- (NSString*) getListId
{
T
if ( ... != nil)
{
return ...;
}
else
{
return @"";
}
}
I cannot figure out what the problem is when I am calling the method.
当我调用该方法时,我无法弄清楚问题是什么。
回答by wattson12
have you added a declaration for this method in the .h file, and if so, have you imported the .h into the file you are trying to call this method?
您是否在 .h 文件中添加了此方法的声明,如果是,您是否已将 .h 导入到您尝试调用此方法的文件中?
this error is basically the compiler saying it can't find the method declaration, so it doesn't know what to expect the return type to be.
这个错误基本上是编译器说它找不到方法声明,所以它不知道返回类型是什么。
回答by janusfidel
in your DeviceList.h , make sure you have
在你的 DeviceList.h 中,确保你有
@interface DeviceList : Parent
- (NSString*) getListId;
..
..
@end
the warning occurs when your method is not declared in your header file and you try to call it outside your (self) class.
当您的方法未在您的头文件中声明并且您尝试在您的(自我)类之外调用它时,会出现警告。