问题描述:

I am just starting out, and would like to use storyboard to create the constraints and positioning of my UI elements, and handle all navigation in code.

One of the first things that I wan to do is create a tab bar and navigation bar programatically and load a viewcontroller with a xib in between them.

I was able to load an empty tableview controller between the navigation bar and the tab bar, as I wanted.

On my custom controller with layout specified in a .xib file, the layout elements from the xib are displayed, the tab bar is working fine, but navigation bar does not show like it does for the tableview controller tab section.

(In appdelegate)

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

let sampleViewController: TestViewController = TestViewController(nibName: "TestViewController", bundle: nil)

let navigationBar = UINavigationController(rootViewController: sampleViewController)

let genericTableViewController = TableViewController()

let navigationBar2 = UINavigationController(rootViewController: genericTableViewController)

let tabBarController = UITabBarController()

let controllers = [navigationBar, navigationBar2]

tabBarController.viewControllers = controllers

navigationBar.tabBarItem = UITabBarItem(

title: "Test",

image: UIImage(named: "ico_settings"),

tag: 1)

navigationBar2.tabBarItem = UITabBarItem(

title: "Just Tableview",

image: UIImage(named: "ico_user"),

tag: 1)

self.window!.rootViewController = tabBarController

self.window!.makeKeyAndVisible()

相关阅读:
Top