【问题标题】:Instance method not found (return type defaults to id)未找到实例方法(返回类型默认为 id)
【发布时间】:2012-10-31 08:50:27
【问题描述】:

我收到了来自 Xcode 的警告。这是代码

 DeviceList *dList = (DeviceList* )[[User thisUser] devices];
 [dList getListId];

警告指出找不到实例方法 -getListId。但是该方法存在于我的源代码中

- (NSString*) getListId
{
    T
    if ( ... != nil)
    {
        return ...;
    }
    else
    {
        return @"";
    }
}

当我调用该方法时,我无法弄清楚问题出在哪里。

【问题讨论】:

    标签: iphone objective-c ios xcode


    【解决方案1】:

    您是否在 .h 文件中添加了此方法的声明,如果是,您是否将 .h 导入到您尝试调用此方法的文件中?

    这个错误基本上是编译器说它找不到方法声明,所以它不知道返回类型是什么。

    【讨论】:

    • 这为我解决了。我在头文件中完成了@class DeviceList;,但在实现中没有完成#import "DeviceList.h"
    【解决方案2】:

    在你的 DeviceList.h 中,确保你有

    @interface DeviceList : Parent
    - (NSString*) getListId;
    ..
    ..
    @end
    

    当你的方法没有在你的头文件中声明并且你试图在你的(self)类之外调用它时,就会出现警告。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-07-14
      • 2013-04-17
      相关资源
      最近更新 更多