UINavigationBar没有显示

时间:2018-06-17 06:26:44

标签: swift uinavigationcontroller uinavigationbar

我有一个快速的项目程序化,从mapview到另一个视图。在segue之后,导航栏不存在。由于文件是从早期的项目中复制过来的,而这种情况并没有发生,我感到很困惑。它应该非常直接。

在AppDelegate中:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.
    window = UIWindow(frame: UIScreen.main.bounds)
    let homeViewController = MapViewController()

    self.navigationController = UINavigationController()
    self.navigationController?.setNavigationBarHidden(false, animated: false)
    navigationController?.viewControllers = [homeViewController]
    self.window!.rootViewController = navigationController
    self.window?.makeKeyAndVisible()

    let attributes = [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue-Light", size: 17)!]
    UINavigationBar.appearance().titleTextAttributes = attributes

    return true
}

在MapViewController中调用segue代码:

    let storeViewController = ViewController()
    let appDelegate = UIApplication.shared.delegate as! AppDelegate
    appDelegate.navigationController?.setNavigationBarHidden(false, animated: false)
    appDelegate.navigationController?.pushViewController(storeViewController, animated: true)

1 个答案:

答案 0 :(得分:0)

您必须在UINavigationController中嵌入MapViewController并根据需要推送ViewControllers

隐藏使用self.navigationController?.isNavigationBarHidden = false

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.

            // Override point for customization after application launch.
            window = UIWindow(frame: UIScreen.main.bounds)

            let homeViewController = MapViewController()
            let navController  = UINavigationController(rootViewController: homeViewController)

            self.window!.rootViewController = navController
            self.window?.makeKeyAndVisible()

            let attributes = [NSAttributedStringKey.font: UIFont(name: "HelveticaNeue-Light", size: 17)!]
            UINavigationBar.appearance().titleTextAttributes = attributes

        return true
    }

并在MapViewController

导航:

    let storeViewController = ViewController()
    self.navigationController?.pushViewController(storeViewController, animated: true)

    //if you want to hide or show navigation
   //self.navigationController?.isNavigationBarHidden = false // true