简体   繁体   English

如何链接到情节提要Xcode的另一个视图

[英]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. 它使用用户ID代替用户名和密码。 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. 我已经有了一条if语句来检查用户ID,以查看它是否正确。 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. 第一个是创建一个直接将登录按钮链接到新视图控制器的segue。 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. 然后,您可以在界面生成器中单击segue中间的小圆圈,为其命名并指定类型。

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. 另外,如果您使用代码创建了登录按钮,或者只是想对您的segue进行更多控制,则可以在界面构建器中创建通用segue,这意味着只需控制从一个视图控制器到另一个视图控制器的拖动。 If you do it this way, YOU MUST NAME THE SEGUE so you have a way to invoke it later. 如果您采用这种方式,则必须命名SEGUE,以便以后可以调用它。 Then you just call [self performSegueWithIdentifier:@"nameOfYourSegue" sender:self]; 然后,您只需调用[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. 如果您需要完全配置新的视图控制器或为其提供任何数据,则应在prepareForSegue:方法中进行。

Here's a link to a nice tutorial on segues: 这是一个有关segues的不错的教程的链接:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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