Warning: Attempt to present UINavigationController on NavigationController which is already presenti

在iOS8中,弹出ActionSheet后选择其中一项,然后在ActionSheet的代理方法actionSheet(actionSheet:clickedButtonAtIndex:)中使用了performSegueWithIdentifier方法来跳转到下一个ViewController时,发现ViewController不但没有跳转,控制台却出现了以下警告:

Warning: Attempt to present <UINavigationController: 0x13c57ecd0> on <XXViewController: 0x13c580d10> which is already presenting (null)

然而在iOS7中一切都正常,也不会出现任何警告。出现这种问题的原因是:

Actionsheets and AlertViews were refactored to AlertControllers (iOS8 only), which are both being presented. So, basically, you’re trying to present a controller where you already have a controller presented (ActionSheet), but by the time the debugger gets it, it’s deallocated and it becomes null, producing the warning you see.


以下是解决办法

  • 1.跳转ViewController这种类型的代码最好写到actionSheet(actionSheet:, didDismissWithButtonIndex)方法中,保证ActionSheet消失后才跳转。

  • 2.如果确实需要在actionSheet(actionSheet: clickedButtonAtIndex: )就跳转,那么可以做个延时,比如0.1秒之后再调用performSegueWithIdentifier方法。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值