Ios 是否可以在模态视图控制器上使用UIAlertController?

Ios 是否可以在模态视图控制器上使用UIAlertController?,ios,uiviewcontroller,uiactionsheet,uialertcontroller,Ios,Uiviewcontroller,Uiactionsheet,Uialertcontroller,我有一个显示的(模态)视图控制器,它需要显示一个操作表。但是,当我这样做时: UIAlertController *actionSheet = [UIAlertController alertControllerWithTitle:nil message:nil preferredStyle:UIAlertControllerStyleActionSheet]; ... [self presentViewController:actionSheet animated:YES completi

我有一个显示的(模态)视图控制器,它需要显示一个操作表。但是,当我这样做时:

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)
警告:尝试呈现已呈现的内容(null)

这里有解决办法吗?使用呈现视图控制器的警报或操作表似乎是一种非常常见的场景。

我认为您正在尝试显示呈现视图控制器的
viewdiload
中的操作表。这就是控制器中未显示操作表的原因,因为控制器的视图尚未加载。因此,如果您正在这样做,那么编写这些代码以在
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];

}

快乐编码…

您在何时何地尝试调用问题中的代码?显示更多上下文。@rmaddy在显示的视图控制器上按下按钮时。这应该可以工作。问题不在这里。您可以创建一个示例项目,该项目显示一个模式,该模式又显示一个操作表。如果失败,请发布代码。