我有一个呈现的(模态) View Controller ,需要呈现一个操作表。但是当我这样做时:
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet];
...
[self presentViewController:actionSheet animated:YES completion:nil];
我明白了:
Warning: Attempt to present <UIAlertController: 0x7fed4a608120> on <MyViewController: 0x7fed4d1ca520> which is already presenting (null)
这里有解决方法吗?从呈现的 View Controller 中使用警报或操作表似乎是一种非常常见的场景。
最佳答案
我认为您正在尝试显示呈现 View Controller 的 viewDidLoad
中的操作表。这就是 Controller View 尚未加载时未在 Controller 中显示操作表的原因。因此,如果您这样做,请编写这些代码以在您的 voewDidAppear
方法中显示操作表,它会按预期显示操作表。
这是代码片段。我已经对其进行了测试,它正在运行。
代码:
- (void)viewDidAppear:(BOOL)animated
{
UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:@"Hello" message:nil preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[actionSheet addAction:ok];
[self presentViewController:actionSheet animated:YES completion:nil];
}
快乐编码......
关于ios - 可以在模态视图 Controller 上使用 UIAlertController 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39537621/