Presenting a view controller modally from an action sheet's delegate in iOS8 - iOS11

前端 未结 9 2011
我寻月下人不归
我寻月下人不归 2020-12-01 01:43

So I noticed that in iOS8 beta 3 (Update: still happens in iOS 11.2) on iPad, when attempting to present a view controller from within a delegate method of

9条回答
  •  一向
    一向 (楼主)
    2020-12-01 02:13

    Update: As of iOS 9 SDK, UIActionSheet is deprecated, so do not expect a fix regarding this issue. It is best to start using UIAlertController when possible.


    The problem seems to come from Apple's switch to using UIAlertController internally to implement the functionality of alert views and action sheets. The issue is seen mostly on iPad and action sheets, because on iPad, action sheets are presented as a popover within a specified view, and what Apple does is travel the responder chain until it finds a view controller and calls presentViewController:animated:completion: with the internal UIAlertController. The problem is less obvious on iPhone and with alert views, because there Apple actually creates a separate window, an empty view controller and presents the internal UIAlertController on top of that, so it seems to not interfere with other presentation.

    I have opened bug report for this issue: rdar://17742017. Please duplicate it and let Apple know this is a problem.

    As a workaround, I recommend delaying the presentation until the next runloop, using the following method:

    dispatch_async(dispatch_get_main_queue(), ^ {
        [self presentViewController:vc animated:YES completion:nil];
    });
    

提交回复
热议问题