ReasyEasyPeasy ReasyEasyPeasy - 6 months ago 23
iOS Question

display a UIViewController in a container

I have a UIViewController. In this UIViewcontroller ist a container. In this container is a Tab Bar Controller. One of the Tabs is a PageViewController embed in a Navigation Controller. One of the Pages is UITableViewController.


If you click on one of the Cells I want to display a UIViewContoller. But this UIViewcontroller should be only in the container and in the NavigationController. If I click on a Cell you can see for 0.3 sec the right result. With a "back" button at the navigation bar. But then the UIViewController switch to full size.

I display the UIViewController as follows:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("article")
self.presentViewController(vc, animated: true, completion: nil)

I get the following Waring:

Presenting view controllers on detached view controllers is discouraged <Test.AllArticlesTableViewController: 0x7f812bd227d0>.

I hope someone can help me.


Presenting a view controller will take up the full screen by default. I believe what you're looking for is to push the view controller onto the navigation stack. Use pushViewController(_:animated:).


self.navigationController.pushViewController(vc, animated: true)

"Pushing a view controller causes its view to be embedded in the navigation interface."

Please refer to the Apple docs for more information.