We have answer of your question!

100% solved queries, no empty question



I am building a Swift 3 app with the following Storyboard:

enter image description here

On the left (in green) is a UIPageViewController that holds the 2 NavigationController as 2 pages. This allows the user to swipe between 2 subparts of the app.

The problem is the following. I'm trying to display an alert in tha black UIViewController.

Here is the code to display the alert:

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)

It works but I always get the the below warning:

Presenting view controllers on detached view controllers is discouraged

I also tried with DispatchQueue.main.async to present the view but I ran into the same warning.

However what I found is, if I set the NavigationController (bottom one) as the initial view controller, it works without the warning.

So, does using a UIPageViewController mean the pages will be kind of detached ?

What am I missing here ? Do I forgot to link stuff ?

Question author Vpusher | Source




You can try following.

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

When you are done you can dismiss it.

[self dismissViewControllerAnimated:YES completion:nil];

Let me know if this works.

Answer author Nitinsh99


Tickanswer.com is providing the only single recommended solution of the question AlertViewController within UIPageViewController under the categories i.e ios , swift , uipageviewcontroller , uialertcontroller , . Our team of experts filter the best solution for you.

Related Search Queries:

You may also add your answer!