解除模态视图控制器提供的UIAlertController
我似乎遇到了一个类似的问题在一个未解决的发布的问题: UIAlertController解雇他的presentsViewController
我在一个普通的UIViewController上展示了一个模态视图控制器。 然后我popup一个模式视图控制器的警报。 当我按下“ok”closures警报(由下面的代码生成)时,模态视图控制器也被解除。
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action{ [self dismissViewControllerAnimated: YES completion: nil];}]; UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"Sign up problem." message:@"Some fields are empty. Please check your inputs and try again." preferredStyle:UIAlertControllerStyleAlert]; [alert addAction:ok]; [self presentViewController:alert animated:YES completion:nil];
我怎样才能解雇警报?
我意识到我可以通过使用导航控制器types设置来避免这个问题,而隐藏导航栏,所以我得到了与模态视图控制器相同的感觉,但这似乎很愚蠢。 谢谢。
不要在button处理程序中调用self dismissViewController
。 具体地说,你想要视图控制器解雇。
您不需要closures警报。 它会自动解散。 你应该在button处理程序中做的唯一事情就是执行你需要的任何操作。 如果你不需要做任何事,就什么都不要做。
如果您的提醒只是一条消息,而您不需要执行任何操作,只需执行以下操作:
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
您不需要在button处理程序中以任何方式手动解除或移除UIAlertController
– 它本身就是这样做的。
只要删除调用dismissViewControllerAnimated:completion:
。