How to open another viewControler on Swift?

Asked

Viewed 1,406 times

2

I’m new to Swift programming and I’m having a doubt. I have two files The main one: Viewcontroller.Swift and another one I created called Viewsegundo.Swift.

I took the class

import UIKit

class ViewSegundo: UIViewController {

    @IBOutlet weak var img4: UIImageView!

    override func viewDidLoad() {


    }
}

I pointed it in the custom class of the second View, when using the right mouse button on the button and Seto to second view works, more I need to do via code, and do not know how to do.

1 answer

1

To open a new controller you need to write like this inside a button click event:

 self.performSegueWithIdentifier("SegundaViewController", sender:self)

You can also do in visual form, which would be by dragging the button to the view and selecting push

  • Thanks Gabriel, now yes with your tip I saw that in addition to the code I needed to identify the storyboard follows with the name of the second View then I pulled from the main View the link to another view I gave the name and used the code and it all worked out.

  • 2

    @user1649307 if it worked mark the answer as accepted, so that people can identify that the answer solved their problem.

  • How about a tour SO ? http://answall.com/tour

Browser other questions tagged

You are not signed in. Login or sign up in order to post.