Open a new screen when a button is pressed in quick

I'm new to swift iOS. In my storyboard, I created some dynamic fields from viewController. Created a button from the library of objects.

Now I have to open a new blank screen after clicking this button. Input fields appear on a new screen. I will create them through programming or an object library.

But I can not open a blank screen.

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

}

I need to enable the screen open code in SaveTgw. Any help or any descriptive link to the tutorial would be appreciated ....

+5
source share
5 answers

1-From the utilities, open the inspector's identity in the storyboard ID, enter the identifier "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);
}
+4

SecondViewController Main.storyboard -

enter image description here Scan ,

@IBAction func scanAction(sender: AnyObject) {
     let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)

let secondViewController = storyBoard.instantiateViewControllerWithIdentifier("SecondViewController") as SecondViewController
self.presentViewController(secondViewController, animated:true, completion:nil) 
}

, -

+1

. segue firstViewController secondViewController. segue goto show ( 3- ). " ". .       performSegueWithIdentifier ( " ", : )

+1
source

just use it with Swift code 2,3x, 4x

if the pib exists, let vc =

YourViewControllerName(nibName:"YourViewControllerName",bundle:nil)
    self.navigationController?.pushViewController(vc,animated:true)

if there is no pen

let vc = YourViewControllerName()
self.navigationController?.pushViewController(vc,animated:true)
+1
source

SWIFT 4

Based on @AbedalkareemOmreyh answer:

  1. Go to Utilities, open the Identity Inspector and enter the identifier "MySecondSecreen" in the storyboard identifier.
  2. Add the following code to your button:

    @IBAction func SaveTgw(sender: AnyObject) {
       let storyboard = UIStoryboard(name: "Main", bundle: nil);
       let vc = storyboard.instantiateViewController(withIdentifier: "MySecondSecreen")
                  self.present(vc, animated: true, completion: nil);
    }
    
0
source

Source: https://habr.com/ru/post/1650115/


All Articles