为什么当我用空 View Controller 创建导航 Controller 时,我收到导航栏的奇怪行为?
这就是我创建导航 Controller 的方式。
init(
window: UIWindow,
keystore: Keystore,
navigationController: UINavigationController = UINavigationController()
) {
self.navigationController = navigationController
self.keystore = keystore
super.init()
window.rootViewController = navigationController
window.makeKeyAndVisible()
}
比我更简单:
func start() {
let x = UIViewController()
x.view.backgroundColor = UIColor.red
navigationController.setViewControllers([x], animated: true)
}
最佳答案
可能是这种情况,因为您在应用已经启动后设置了 NavigationController。
我建议在您的 AppDelegate 中设置 NavigationController。
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
let firstViewController = UIViewController()
let navigationController = UINavigationController(rootViewController: firstViewController)
window?.rootViewController = navigationController
window?.makeKeyAndVisible()
return true
}
}
关于swift - 为什么在第一次启动时我的导航栏在状态栏下面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48063691/