I have a tab-bar based app and I want to add Navigation Bar at the top of the app. Please note that I am using a library called PageMenu that creates 2 TableViews inside 1 parent ViewController.
What I tried was, adding a new ViewController and Editor->Embed in Navigation Bar. Place it before Tab Bar Controller, ctrl+drag to Tab Bar Controller to set the relationship of root view. Finally set Nav Bar Controller as initial view controller. But this fails like this:
(Top became pretty weird, blurry and the sub-header of PageMenu got disappeared. Maybe it's under that blurry thing because I can still swipe between 2 table views.
Secondly, I tried removing the Navigation Controller, and add Navigation Bar to the ViewControllers manually. This worked for table view and view controllers but not the PageMenu one. When I tried it on PageMenu Controller, it didn't show any navigation bar.
Please note that, in the Demo, they used Navigation Bar as Parent and sub-TableViews, and they achieved Navigation Bar with this as well as Storyboard > Navigation Controller:
override func viewDidLoad() {
super.viewDidLoad()
self.title = "HEADER"
self.navigationController?.navigationBar.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.whiteColor()]
self.navigationController?.navigationBar.tintColor = UIColor.whiteColor()
}
Lastly, I tried..
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let nav1 = UINavigationController()
let first = ViewController(nibName: nil, bundle: nil)
nav1.viewControllers = [first]
let second = SecondViewController(nibName: "SecondViewController", bundle: nil)
let nav2 = UINavigationController()
nav2.viewControllers = [second]
let tabs = UITabBarController()
tabs.viewControllers = [nav1, nav2]
self.window!.rootViewController = tabs;
self.window?.makeKeyAndVisible();
return true
}
But the result I get is:
What I want to achieve (but with TabBarController; NavBar just for header):
What I have now is this. I just want to add NavigationBar at the top of it like the above PageMenu example
Update: Lasly, I also tried:
But same issue:
You can also create like wise story board that helps to solve your problem.
Here I can created sample code what you want no single line code change but changes into storyboard only.
Download source code from here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With