1. Configure startup items
(Swift3.0)
1. Create a non-NavigationController root view
var window: UIWindow?
var viewController: UIViewController?
func application(_ application: UIApplication.didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow.init(frame: UIScreen.main.bounds)
let vc = ViewController(a)self.viewController = vc
self.window?.rootViewController = self.viewController
self.window?.makeKeyAndVisible()
return true
}
Copy the code
2. Include navigationController root view creation
Method 1
var window: UIWindow?
var viewController: UINavigationController?
func application(_ application: UIApplication.didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
self.window = UIWindow.init(frame: UIScreen.main.bounds)
let vc = ViewController(a)self.viewController = UINavigationController.init(rootViewController: vc)
self.window?.rootViewController = self.viewController
self.window?.makeKeyAndVisible()
return true
}
Copy the code
Method 2 (swift, 4.0)
In the AppDelegate. Swift
window = UIWindow(frame: UIScreen.main.bounds)
let rootVC = ViewController(a)let navrootVC = UINavigationController(rootViewController: rootVC)
window?.rootViewController = navrootVC
window?.makeKeyAndVisible()
Copy the code
SceneDelegate. Swift
guard let winScene = (scene as? UIWindowScene) else { return }
let rootvc = ViewController(a)let rootNav = UINavigationController(rootViewController: rootvc)
let win = UIWindow(windowScene: winScene)
win.rootViewController = rootNav
win.makeKeyAndVisible()
window = win
Copy the code
3. Use storyboard to jump controller code in the AppDelegate
@icelovery func application(application: UIApplication.didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let viewController = storyboard.instantiateViewControllerWithIdentifier("Storybord name")
self.window?.rootViewController = viewController
self.window?.makeKeyAndVisible()
return true
}
Copy the code