UIPageViewController中的AlertViewController

时间:2016-12-09 17:42:35

标签: ios swift uipageviewcontroller uialertcontroller

我正在使用以下Storyboard构建一个Swift 3应用程序:

enter image description here

左侧(绿色)是 UIPageViewController ,它将2 NavigationController 保存为2页。这允许用户在应用的两个子部分之间滑动。

问题如下。我正试图在黑色 UIViewController 中显示警告。

以下是显示提醒的代码:

override func viewDidAppear(_ animated: Bool) {         
    let alert = UIAlertController(title: "Hello", message: "World", preferredStyle: UIAlertControllerStyle.alert)
    alert.addAction(UIAlertAction(title: "Cancel", style: UIAlertActionStyle.cancel, handler: { action in
        alert.dismiss(animated: true, completion: nil)
    }))
    self.present(alert, animated: true, completion: nil)
}

它有效,但我总是得到以下警告:

Presenting view controllers on detached view controllers is discouraged

我也尝试用DispatchQueue.main.async来展示视图,但我遇到了同样的警告。

然而,我发现,如果我将 NavigationController (底部一个)设置为初始视图控制器,它将在没有警告的情况下工作。

那么,使用 UIPageViewController 是否意味着页面会被分离?

我在这里缺少什么?我忘了链接东西吗?

1 个答案:

答案 0 :(得分:1)

您可以尝试以下操作。

[self.view.window.rootViewController presentViewController:alert animated:YES completion:nil];

完成后你可以解雇它。

[self dismissViewControllerAnimated:YES completion:nil];

让我知道这是否有效。

相关问题