Instantiate and Present a viewController in Swift

前端 未结 16 1718
难免孤独
难免孤独 2020-11-22 13:04

Issue

I started taking a look of the new Swift on Xcode 6, and I tried some demo projects and tutorials. Now I am stuck at:

16条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-22 13:16

    // "Main" is name of .storybord file "
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    // "MiniGameView" is the ID given to the ViewController in the interfacebuilder
    // MiniGameViewController is the CLASS name of the ViewController.swift file acosiated to the ViewController
    var setViewController = mainStoryboard.instantiateViewControllerWithIdentifier("MiniGameView") as MiniGameViewController
    var rootViewController = self.window!.rootViewController
    rootViewController?.presentViewController(setViewController, animated: false, completion: nil)
    

    This worked fine for me when i put it in AppDelegate

提交回复
热议问题