具有条件故事板的segue过渡 [英] segue transition with condition storyboard

查看:83
本文介绍了具有条件故事板的segue过渡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是故事板和xcode的新手(使用4.4)

I am new to storyboard and xcode (using 4.4)

我想实现一个登录条件,如果完成了 - segue会起作用。否则,用户应保持相同的视图。

I would like to implement a login condition, that if accomplished - the segue would work. Otherwise, the user should stay on the same view.

我创建了2个UIView:ViewController和Bar Controller。

I created 2 UIView: ViewController and Bar Controller.

我还从ViewController到Bar Controller创建了一个segue,并将其标识符设置为loginSegue作为模态。

I also created a segue from ViewController to Bar Controller and set its identifier to loginSegue as modal.

在LoginViewController.m中我添加了以下内容:

In LoginViewController.m I added the following:

- (IBAction)login:(id)sender {
    self.email = self.emailText.text;
    self.password = self.passwordText.text;
   if ([self.email isEqualToString:@"O"] && [self.password isEqualToString:@"O"])
       [self performSegueWithIdentifier:@"LoginSegue" sender:sender];
    else
        [passwordText setText:@""];   
}

当我调试代码时 - 我看到if跳过其他的情况电子邮件和密码不等于O,但是segue(转换到新视图)仍然会发生。

When I debug the code - I see that the if skips to else in case of email and password that to not equal to O, however the segue (transition to the new view) still happens.

如何阻止用户转移到新视图?

How can I prevent the user to be transferred to the new view?

BTW,如果我删除if else条件 - 用户将自动转移到下一个视图。在我看来,当我将segue从一个视图绘制到另一个视图时,它被配置在某处。

BTW, if I remove the if else condition - the user is being transferred to the next view automatically. It seems to me that it was configured somewhere when I drew the segue from one view to the other.

推荐答案

删除空白行在您的之间 [自我执行...]

此外,您可能需要考虑在大括号中保留 if-else 语句,以防止此问题再次发生:

Additionally, you may want to consider keeping your if-else statements in braces to keep this problem from happening again:

if ([self.email isEqualToString:@"O"] && [self.password isEqualToString:@"O"]){
    [self performSegueWithIdentifier:@"LoginSegue" sender:sender];
}else{
    [passwordText setText:@""];
}

如果这不能解决问题,那么一定要改变segue附加到两个控制器而不是直接连接到按钮。

If this doesn't solve the problem then be sure to varify that the segue is attached to the two controllers and not directly to a button.

这篇关于具有条件故事板的segue过渡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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