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

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

    You can try to do your job (presenting view controller) in

    - (void)      actionSheet:(UIActionSheet *)actionSheet
    didDismissWithButtonIndex:(NSInteger)buttonIndex {}
    

    instead of

    - (void) actionSheet:(UIActionSheet *)actionSheet
    clickedButtonAtIndex:(NSInteger)buttonIndex {}
    

    as @LeoNatan said, "The problem seems to come from Apple's switch to using UIAlertController internally to implement the functionality of alert views and action sheets". So you must to wait the action sheet dismissed, then present the view controller you want.

    @LeoNatan's solution just block the UI at main thread, so it'll also make sure the view controller will be presented after the action sheet was dismissed.

    0 讨论(0)
  • 2020-12-01 02:30

    Try

    [[NSOperationQueue mainQueue] addOperationWithBlock:^{
        // action sheet presentation
        // or modal view controller presentation
        // or alert view presentation
    }];
    
    0 讨论(0)
  • 2020-12-01 02:34

    Issuing a

    [self.navigationController dismissViewControllerAnimated:YES completion:nil];
    

    on

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

    before trying to present another modal view worked for me.

    0 讨论(0)
提交回复
热议问题