UIAlertController 不会弹出



在执行备份过程结束时,我想让用户知道备份已完成。我曾经使用UIAlertView,它有效。然而,它的折旧所以将这些换成UIAlertController。弹出消息完成后,窗口将关闭。新的UIAlertController似乎在这种情况下不起作用。我做错了什么?

这种情况正在发生,并且在视图关闭之前结束了该过程。下面代码的最后一行是关闭视图。UIAlertView 必须是模态的还是阻止视图关闭的东西?

我曾经使用过这段代码,效果很好。

    UIAlertView *myalert = [[UIAlertView alloc] initWithTitle:nil message:Msg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [myalert show];
   [self presentViewController:alert animated:YES completion:nil];

而这个新代码你什么也看不到

  UIAlertController * alert=   [UIAlertController
                                  alertControllerWithTitle:@""
                                  message:Msg
                                  preferredStyle:UIAlertControllerStyleAlert];
    UIAlertAction* okButton = [UIAlertAction
                               actionWithTitle:@"OK"
                               style:UIAlertActionStyleDefault
                               handler:^(UIAlertAction * action)
                               {
                                   [alert dismissViewControllerAnimated:YES completion:nil];
                               }];

    [alert addAction:okButton];

    [self presentViewController:alert animated:YES completion:nil];

   [self dismissViewControllerAnimated:NO completion:nil];

这一行看起来是错误的:

[self dismissViewControllerAnimated:NO completion:nil];

尝试将其删除或放在更合适的位置。我建议您立即提出然后关闭警报。

[self dismissViewControllerAnimated:NO completion:nil];
在显示警报

时删除此行,并快速关闭显示警报的视图。

简而言之,您正在显示警报并删除显示警报的视图

最新更新