【问题标题】:Why does my Xcode recognize optional delegate method as unrecognized selector? [closed]为什么我的 Xcode 将可选委托方法识别为无法识别的选择器? [关闭]
【发布时间】:2012-09-23 15:08:43
【问题描述】:

这是我的崩溃日志。

2012-09-24 00:06:16.711 DMJ[10021:c07] -[DMJAppDelegate application:supportedInterfaceOrientationsForWindow:]: unrecognized selector sent to instance 0x84abe70
2012-09-24 00:06:16.713 DMJ[10021:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[DMJAppDelegate application:supportedInterfaceOrientationsForWindow:]: unrecognized selector sent to instance 0x84abe70'
*** First throw call stack:
(0x2553012 0x1e04e7e 0x25de4bd 0x1e187ea 0x2542cf9 0x254294e 0x82a332 0x91266d 0x90d046 0x90d246 0x85601f 0x476e8e 0x4769b7 0x875573 0x4a1428 0xa420cc 0x1e18663 0x254e45a 0xa40bcf 0xa4298d 0x824ceb 0x825002 0x823ed6 0x835315 0x83624b 0x827cf8 0x2c88df9 0x2c88ad0 0x24c8bf5 0x24c8962 0x24f9bb6 0x24f8f44 0x24f8e1b 0x8237da 0x82565c 0x2ded 0x2d25 0x1)
libc++abi.dylib: terminate called throwing an exception
(lldb)

【问题讨论】:

    标签: objective-c crash selector ios6


    【解决方案1】:

    协议上下文中的可选意味着您不需要实现该方法。 但是你也必须注意不要调用这些方法,否则你会得到一个异常。 通常在调用可选协议方法之前,您会执行以下操作:

    if ([object respondsToSelector:@selector(application:supportedInterfaceOrientationsForWindow:)])
        result = [object application:myApp supportedInterfaceOritentationsForWindow:myWin];
    

    如前所述,该方法可能会被调用,因为您的 info.plist 不包含正确的键 (UIInterfaceOrientation)。

    【讨论】:

      【解决方案2】:

      您是否确保您的 Delegate 类符合 UIApplicationDelegate 协议?

      你的DMJAppDelegate.h 应该有

      @interface DMJAppDelegate : NSObject <UIApplicationDelegate> 
      

      正如Apple Developer Documentation 关于 UIApplicationDelegate 中提到的,如果您的应用程序 Info.plist 没有指定有效方向的键 UIInterfaceOrientation,那么它将调用 supportedInterfaceOrientationsForWindow 给委托(因此在此不是可选的case) 所以如果你没有实现委托方法,你需要确保你已经在 Info.plist 中指定了方向

      当您打开 Info.plist 时,它应该在 Xcode 中指定(如果您正在开发通用应用程序,则为 iPhone 和 iPad 分开)

      或者,您可以通过在项目摘要中选择目标来查看支持的界面方向

      【讨论】:

      • 感谢您的建议。我听从了你的建议。但问题仍然是相同的状态。我该怎么办... :(
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多