【问题标题】:Custom Segue - unrecognized selector sent to instance - setUseDefaultModalPresentationStyle自定义 Segue - 无法识别的选择器发送到实例 - setUseDefaultModalPresentationStyle
【发布时间】:2016-01-07 18:43:35
【问题描述】:

我正在使用这个custom segue。它在 iOS8+ 上完美运行,但是,在 iOS 7 上,我收到此错误。

2015-10-09 13:59:02.891 APPNAME[1790:60b] -[APPNAME.AFBlurSegue setUseDefaultModalPresentationStyle:]: unrecognized selector sent to instance 0x15ddafe0
2015-10-09 13:59:02.901 APPNAME[1790:60b] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[APPNAME.AFBlurSegue setUseDefaultModalPresentationStyle:]: unrecognized selector sent to instance 0x15ddafe0'
*** First throw call stack:
(0x2e5c6f83 0x38d77ccf 0x2e5ca917 0x2e5c9203 0x2e518768 0x312c0381 0x312b63fb 0x30e19037 0x30e18fd7 0x30e18fb1 0x30e04717 0x30e18a2f 0x30e18701 0x30e136cb 0x30de88cd 0x30de6f77 0x2e59220b 0x2e5916db 0x2e58fecf 0x2e4faebf 0x2e4faca3 0x33400663 0x30e4714d 0x13e65c 0x39284ab7)
libc++abi.dylib: terminating with uncaught exception of type NSException
(lldb)

问题是,崩溃是模糊的。我什至尝试在任何地方放置断点并尝试捕获抛出的任何错误。但是,它仍然没有指出错误可能在哪里。

这似乎是一个参数/选择器错误,我怀疑这可能是一个 Swift 2 错误。我唯一能找到 setUseDefaultModalPresentationStyle 参考的地方是here

任何帮助将不胜感激!

【问题讨论】:

  • 您可以尝试在AFBlurSegue 中覆盖该方法并在其中放置一个断点,以便您可以看到调用它的堆栈跟踪。可能有助于弄清楚发生了什么。
  • 我试过这个,我什至用 Swift 逐行重写了“AFBlurSegue.m”。仍然无法看到堆栈跟踪。

标签: ios objective-c swift ios7 segue


【解决方案1】:

这是因为这个库使用UIVisualEffectView 来获得模糊效果。很遗憾,UIVisualEffectView 仅适用于 iOS 8 及更高版本

请参阅 documentation 了解更多信息。

不幸的是,如果您想使用花哨的模糊过渡,您的应用将无法与 iOS 7 及更低版本兼容,这不是什么大问题,因为目前只有 10% 的设备具有低于 iOS 8 的 iOS。

More info here

解决方案:

您可以使用该库的旧版本解决此问题,该版本尚未使用UIVisualEffectView,而是使用UIImage+ImageEffects.m 来获得模糊效果。

【讨论】:

  • 如果您查看库,可以检查它是否为 iOS7 或更高版本。后面部分只用到了UIVisualEffectView,对于iOS7,它使用普通的UIImageView和UIImage+ImageEffects.m进行模糊。
  • 实际上,查看其中的检查代码适用于 iOS 版本
  • 我没有注意到这一点。但是,由于我确实在 Swift 中编写了这个端口,所以我已经完成了这个检查,但它仍然失败。你可以在这里看到端口:gist.github.com/jathu/9aa35c2f4d7fb32159ff
【解决方案2】:

尝试在情节提要的 segue 上将 Segue 设置设置为 Custom,并以编程方式设置样式:

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIViewController *destination = segue.destinationViewController;
    destination.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-06-13
    • 2013-02-21
    • 1970-01-01
    • 1970-01-01
    • 2019-08-28
    • 2012-07-24
    相关资源
    最近更新 更多