简体   繁体   中英

Tab Bar and Navigation Bar won’t show when the ViewController is moved

I have a ViewController (without Tab Bar and Navigation Bar) in a Storyboard that I need to move to another ViewController (with Tab Bar and Navigation Bar). The problem is I'm able to move to the ViewController but it won't show the Tab Bar and the Navigation Bar.

Here's how I do it:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let feedTableViewController = storyboard.instantiateViewController(withIdentifier: "Feed") as! FeedTableViewController
self.navigationController?.pushViewController(feedTableViewController, animated: true)

I've tried embedding Navigation Bar and Tab Bar to the first ViewController but I'm without luck. What's the right way to do this?

I found my way around it.

Instead of initiating the ViewController that I wanted to display. I initiated the TabBarController and then displayed it, like:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarViewController = storyboard.instantiateViewController(withIdentifier: "TabBarIdentifier")
self.show(tabBarViewController, sender: nil)

Also, if a NavigationController is not already initialized, we could do so by:

let storyboard = UIStoryboard(name: "Main", bundle: nil)
let tabBarViewController = storyboard.instantiateViewController(withIdentifier: "TabBarIdentifier")
let targetNavigationController = UINavigationController(rootViewController: tabBarViewController)
self.show(targetNavigationController, sender: nil)

The latter part overlaps the already embedded NavigationController in Storyboard, though. Feel free to comment if there's anything that you want to add.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM