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

前端 未结 9 2022
我寻月下人不归
我寻月下人不归 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

    In iOS 8 Apple uses UIAlertController internally to implement the functionality of alert views and action sheets. So when you want to show a UIViewController modally after displaying UIActionSheet or UIAlertView in delegate method like

    (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    

    and

    (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
    

    you have to first dismiss UIAlertController as follows:

    if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
    {
        UIViewController *vc = [[[[UIApplication sharedApplication] delegate] window] rootViewController];
        [vc dismissViewControllerAnimated:NO completion:^{
    
        }];
    }
    

    Now you can present a modal UIViewController in iOS 8.

提交回复
热议问题