如何链接到故事板 Xcode 的另一个视图

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17202245/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:31:35  来源:igfitidea点击:

How to link to another view of storyboard Xcode

iosxcodeviewhyperlinkstoryboard

提问by user2501551

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.

我创建了一个登录系统。它使用用户 ID 而不是用户名和密码。我想这样做,当按下登录按钮时,它会在我的故事板中打开另一个视图控制器。我已经有一个 if 语句检查用户 ID 以查看它是否正确。我只需要知道执行的方法。我已经尝试了一些,但我需要更多关于如何使用它们的解释。

回答by mrosales

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.

有几种方法可以做到这一点。第一个是创建一个 segue,将登录按钮直接链接到新的视图控制器。如果您想这样做,请右键单击从按钮拖动(或控制拖动)到新的视图控制器。这应该使一条灰线从第一个控制器延伸到第二个控制器。然后,您可以在界面构建器中单击 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. 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.

或者,如果您使用代码创建了登录按钮,或者只是想对您的 segue 进行更多控制,您可以在界面构建器中创建一个通用 segue,这意味着只需控制从一个视图控制器到另一个视图控制器的拖动。如果您这样做,则您必须为 SEGUE 命名,以便您以后可以调用它。然后你只需打电话[self performSegueWithIdentifier:@"nameOfYourSegue" sender:self];来让 segue 发生。

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/