美文网首页程序员iOS DeveloperiOS程序猿
Swift | iOS开发之Swift入门-AppDelegat

Swift | iOS开发之Swift入门-AppDelegat

作者: Fiona_L | 来源:发表于2016-11-10 15:56 被阅读2624次

    在进行iOS开发时,和之前使用OC一样,默认使用storyboard,所以无需在AppDelegate中进行任何操作(push除外)。

    不使用storyboard的纯代码需要增加如下代码:(文中代码为swift3.0)
    1. 非navigationController
        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()
            self.viewController = vc
            self.window?.rootViewController = self.viewController
            self.window?.makeKeyAndVisible()
            return true
        }
    
    1. navigationController
        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()
            self.viewController = UINavigationController.init(rootViewController: vc)
            self.window?.rootViewController = self.viewController
            self.window?.makeKeyAndVisible()
            return true
        }
    

    相关文章

      网友评论

        本文标题:Swift | iOS开发之Swift入门-AppDelegat

        本文链接:https://www.haomeiwen.com/subject/zgzgyttx.html