如何制作Segue Pass数据并且仅在满足某些条件时才执行 [英] How to make Segue Pass Data AND ONLY execute if certain criteria is met

查看:85
本文介绍了如何制作Segue Pass数据并且仅在满足某些条件时才执行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带按钮的登录页面。当我点击它时,IF和ONLY如果登录成功,我想将数据传递给另一个类(使用属性)。

I have a Login page with a button. When I click on it, IF and ONLY IF the login was successful, I want to pass data to another class (using properties).

我试过使用Segue on用于传递数据的Button,但问题是此Segue总是进入下一个View,即使登录失败也是如此,在这种情况下它不应该。

I have tried using a Segue on the Button to pass the data, but the problem is that this Segue always goes to the next View, EVEN when the login is unsuccessful, in which case it should NOT.

 -(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {            
if ([[segue identifier] isEqualToString:@"gotoMainPage"] ) {
MainPageController *mpc = [segue destinationViewController];     
mpc.username = @"TEST";    }

如果登录成功,我如何才能使Segue只进入destinationController?

How can I make the Segue ONLY go to the destinationController, if the login is successful ?

我知道还有其他方法可以转到另一个ViewController,例如在按钮上设置IBAction,当登录成功时,使用instantiateViewControllerWithIdentifier和presentViewController,我有尝试过这些,但问题是,它不会将数据传递给另一个类。

I am aware that there are other ways to go to another ViewController, such as setting an IBAction on the button, and when login is successful, use instantiateViewControllerWithIdentifier and presentViewController, and I HAVE tried with those too, but the issue here is that, it does NOT pass the data to another class.

帮助表示赞赏。谢谢

推荐答案

您从控制器(而非按钮)连接segue,然后在满足条件后,调用performSegueWithIdentifier in代码。

You connect the segue from the controller (not a button), and then after your condition is met, call performSegueWithIdentifier in code.

这篇关于如何制作Segue Pass数据并且仅在满足某些条件时才执行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆