0

i want to create navigation bar but nothing happens

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    let viewController = DummyViewController(nibName: nil, bundle: nil) 
    let navigationController = UINavigationController(rootViewController: viewController)

    self.window = UIWindow(frame: UIScreen.main.bounds)
    self.window?.rootViewController = navigationController
    self.window?.makeKeyAndVisible()

    let tabBarController = UITabBarController()
    let tabViewController1 = DummyViewController(
        nibName: "DummyViewController",
        bundle: nil)
    let tabViewController2 = SearchViewController(
        nibName:"SearchViewController",
        bundle: nil)

    tabViewController1.tabBarItem = UITabBarItem(
        title: "Location",
        image: UIImage(named: "ic_location_blue"),
        tag: 1)
    tabViewController2.tabBarItem = UITabBarItem(
        title: "Search",
        image:UIImage(named: "ic_search_blue") ,
        tag:2)


    let controllers = [tabViewController1,tabViewController2]
    tabBarController.viewControllers = controllers
    window?.rootViewController = tabBarController

    return true
}

it seems because i add self.window?.rootViewController = navigationController and window?.rootViewController = tabBarController

i'm using xib file, and don't know how to use tab bar controller with navigation controller together, thanks before.

1
  • Then programatically OR in xib? Commented Jan 19, 2017 at 12:07

3 Answers 3

2

you could try this

let viewController = DummyViewController(nibName: nil, bundle: nil)
let navigationController = UINavigationController()
navigationController.viewControllers = [viewController!]
self.window!.rootViewController = navigationController
self.window?.makeKeyAndVisible()

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

1

solved using

let FirstViewController: HomeViewController = HomeViewController(nibName: "HomeViewController", bundle: nil)
    let navigationBarFirst = UINavigationController(rootViewController: FirstViewController)

    let SecondViewController: SearchViewController = SearchViewController(nibName: "SearchViewController", bundle: nil)
    let navigationBarSecond = UINavigationController(rootViewController: SecondViewController)

    let ThirdViewController: InformationViewController = InformationViewController(nibName: "InformationViewController", bundle: nil)
    let navigationBarThird = UINavigationController(rootViewController: ThirdViewController)

    let FourthViewController: FavoritesViewController = FavoritesViewController(nibName: "FavoritesViewController", bundle: nil)
    let navigationBarFourth = UINavigationController(rootViewController: FourthViewController)

    let FifthViewController: MenuViewController = MenuViewController(nibName: "MenuViewController", bundle: nil)
    let navigationBarFifth = UINavigationController(rootViewController: FifthViewController)

    let tabBarController = UITabBarController()

    let controllers = [navigationBarFirst, navigationBarSecond, navigationBarThird, navigationBarFourth, navigationBarFifth]

Comments

0

You are writing the nil as nib name. Enter the nib name as follows:-

let viewController = DummyViewController(nibName: "DummyViewController", bundle: nil)

3 Comments

Try to add this line too:- navigationController.navigationBar.translucent = false
i try to add navigationController.navigationBar.translucent = false under let navigationController = UINavigationController(rootViewController: viewController) in appDelegate. Still doesn't work
Check my answer on your new question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.