segue transition with condition storyboard

狂风中的少年 提交于 2019-12-19 05:01:28

问题


I am new to storyboard and xcode (using 4.4)

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

I created 2 UIView: ViewController and Bar Controller.

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

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:@""];   
}

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 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.


回答1:


Delete the blank line in between your if and [self perform...]

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:@""];
}

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.



来源:https://stackoverflow.com/questions/12179608/segue-transition-with-condition-storyboard

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!