Sun*_*ons 7 objective-c ios uialertcontroller
我似乎遇到了类似于一个未解决的问题中的问题:UIAlertController解雇他的presentViewController
我在普通的UIViewController上呈现模态视图控制器.然后我在该模态视图控制器上弹出警报.当我按"ok"关闭警报(使用下面的代码生成)时,模态视图控制器也被解除.
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];
Run Code Online (Sandbox Code Playgroud)
我该如何解除警报?
我意识到我可以通过使用导航控制器类型设置而隐藏导航栏来避免这个问题,所以我得到了与模态视图控制器相同的感觉,但这看起来很傻.谢谢.
rma*_*ddy 21
不要self dismissViewController在按钮处理程序中调用.这特别声明您希望视图控制器被解雇.
您无需关闭警报.它会自动解散自己.您应该在按钮处理程序中执行的唯一操作是执行您需要的任何操作.如果你不需要做任何事情,什么也不做.
如果您的警报只是一条消息而您不需要执行任何操作,请执行以下操作:
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:nil];
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15216 次 |
| 最近记录: |