ripa ripa - 4 months ago 11
iOS Question

open new screen on button click in swift

I'm newbie in

swift iOS
. In my storyboard, I've created some dynamic fields from
viewController
. Have created a button from object library.

Now I need to open an new empty screen after clicking this button.
In the new screen, there'll be some input fields. I'll create those through programming or object library.

But I'm unable to open the empty screen.

@IBAction func SaveTgw(sender: AnyObject) {
print("test=====")

}


I need to include the screen opening code within
SaveTgw
. Any help or any descriptive tutorial link would be appreciated....

Answer

1-From Utilities open identity inspector in storyboard ID enter id "MySecondSecreen"

enter image description here


2-In your method add the following code :

@IBAction func SaveTgw(sender: AnyObject) {
        let storyboard = UIStoryboard(name: "Main", bundle: nil);
        let vc = storyboard.instantiateViewControllerWithIdentifier("MySecondSecreen") as! UIViewController; // MySecondSecreen the storyboard ID
        self.presentViewController(vc, animated: true, completion: nil);
}