How to transition to a new view controller with code only using Swift

后端 未结 9 1557
半阙折子戏
半阙折子戏 2020-12-23 08:58

I want to transition from ViewController to secondViewController, when the user presses a UIButton, using code only in Swift.

//Function to transition
func          


        
9条回答
  •  北荒
    北荒 (楼主)
    2020-12-23 09:46

    Updated for Swift 3, some of these answers are a bit outdated.

    let mainStoryboard = UIStoryboard(name: "Main", bundle: Bundle.main)
            let vc : UIViewController = mainStoryboard.instantiateViewController(withIdentifier: "myStoryboardID") as UIViewController
            self.present(vc, animated: true, completion: nil)    }
    

提交回复
热议问题