简体   繁体   中英

How to link to another view of storyboard Xcode

I have a login system created. It uses a user ID instead of username and password. I want to make it so when the login button is pressed, it opens another view controller in my storyboard. I already have an if statement checking the user ID to see if it is correct. I just need to know the method to perform. I have tried a few, but I need more explanation of how to use them.

There are a couple of ways to do this. The first is to create a segue that directly links the login button to the new view controller. If you want to do this, right click drag (or control drag) from the button to the new view controller. This should make a grey line going from the first controller to the second one. You can then click on the little circle in the middle of the segue in interface builder to give it a name and specify the type.

Alternatively, if you created the login button with code, or would just like more control over your segues, you can create a generic segue in interface builder, meaning just control drag from one view controller to the other. If you do it this way, YOU MUST NAME THE SEGUE so you have a way to invoke it later. Then you just call [self performSegueWithIdentifier:@"nameOfYourSegue" sender:self]; to make the segue happen.

If you need to configure the new view controller at all or give it any data, this should happen in the prepareForSegue: method.

Here's a link to a nice tutorial on segues:

http://www.appcoda.com/storyboards-ios-tutorial-pass-data-between-view-controller-with-segue/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM