在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
方法。