【问题标题】:How to resolve unrecognized selector sent to class?如何解决发送到班级的无法识别的选择器?
【发布时间】:2011-03-19 17:52:03
【问题描述】:

我的问题类似于This SO question,但主要区别在于我使用的是类方法。一些代码:

OpenFeint+private.h

@interface OpenFeint (Private)
// ...
+ (void) createSharedInstance;

OpenFeint+private.mm

+ (void) createSharedInstance
{
   //...
}

OpenFeint.mm

+ (void) initializeWithProductKey:(NSString*)productKey 
       andSecret:(NSString*)productSecret 
       andDisplayName:(NSString*)displayName
       andSettings:(NSDictionary*)settings 
       andDelegates:(OFDelegatesContainer*)delegatesContainer
{
    [OpenFeint createSharedInstance];
    // ...

MyApp.mm:

// ...
#import "OpenFeint.h"
// ...
[OpenFeint initializeWithProductKey: OF_PRODUCT_KEY 
        andSecret: OF_PRODUCT_SECRET
        andDisplayName: OF_DISPLAY_NAME
        andSettings: openFeintSettings
        andDelegates: [OFDelegatesContainer containerWithOpenFeintDelegate: self]];

错误是:

2010-07-22 11:30:15.239 MyApp[20210:207] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '+[OpenFeint createSharedInstance]: unrecognized selector sent to class 0x1cdb1c'
*** Call stack at first throw:
(
    0   CoreFoundation                      0x02d6f919 __exceptionPreprocess + 185
    1   libobjc.A.dylib                     0x02ebd5de objc_exception_throw + 47
    2   CoreFoundation                      0x02d714eb +[NSObject(NSObject) doesNotRecognizeSelector:] + 187
    3   CoreFoundation                      0x02ce1116 ___forwarding___ + 966
    4   CoreFoundation                      0x02ce0cd2 _CF_forwarding_prep_0 + 50
    5   MyApp                               0x0002844d +[OpenFeint initializeWithProductKey:andSecret:andDisplayName:andSettings:andDelegates:] + 48
        // ...

一切编译和链接都很好,但我遇到了这个愚蠢的错误。

最后一件事——所有 OpenFeint 的东西都是一个静态库,是的,它也被编译和链接。这是我的第一个静态库,所以我可能只是错过了一些重要的步骤。有什么线索吗?

谢谢!

【问题讨论】:

    标签: iphone static-libraries


    【解决方案1】:

    嗯,我似乎有found a workaround,但我不确定它是否正确。我添加了链接器标志 -all_load(除了 -ObjC),现在似乎一切正常。

    问题修订/添加:这是“合法”修复吗?有更好的吗?

    【讨论】:

    • 是的。那是合法的解决方法。如果您想从静态库中加载所有内容,则必须这样做。
    【解决方案2】:

    OpenFeint+private 是一个类别,所以如果你没有在任何你调用它的地方导入 OpenFeint+private.h 文件,你每次调用它都会得到selector not recognized 错误。就好像您根本没有定义方法一样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多