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

后端 未结 9 1514
半阙折子戏
半阙折子戏 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:43

    For anyone doing this on iOS8, this is what I had to do:

    I have a swift class file titled SettingsView.swift and a .xib file named SettingsView.xib. I run this in MasterViewController.swift (or any view controller really to open a second view controller)

    @IBAction func openSettings(sender: AnyObject) {
            var mySettings: SettingsView = SettingsView(nibName: "SettingsView", bundle: nil) /<--- Notice this "nibName" 
            var modalStyle: UIModalTransitionStyle = UIModalTransitionStyle.CoverVertical
            mySettings.modalTransitionStyle = modalStyle
            self.presentViewController(mySettings, animated: true, completion: nil)
    
        }
    

提交回复
热议问题