【发布时间】:2017-04-14 11:57:45
【问题描述】:
在使用 Xcode 8.3 和 iOS 10.3 的 Swift 3 项目中,我得到了一个导航控制器来推送。该应用程序使用导航控制器运行,直到我尝试使用它来推送。一切正常,直到导致应用程序崩溃的最后一行,fatal error: unexpectedly found nil while unwrapping an Optional value。我不想使用storyboard,这个问题的重点是如何在没有storyboard的情况下完成这个任务。
应用代理代码
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
window = UIWindow(frame: UIScreen.main.bounds)
window?.makeKeyAndVisible()
window?.rootViewController = UINavigationController(rootViewController: MainViewController())
}
视图控制器:
import UIKit
class MainViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .white
let navController = navigationController
let myProfileViewController = MyProfileViewController()
navController!.pushViewController(myProfileViewController, animated: true)
}
}
【问题讨论】:
标签: swift3 uinavigationcontroller