简体   繁体   English

如何通过按钮有条件地调用情节提要面板场景

[英]how to call a storyboard scene conditionally from a button

I have an application who's first scene is a login screen. 我有一个应用程序的第一个场景是登录屏幕。 On pressing the login button, if the username and password are correct, the next scene should get called. 按下登录按钮后,如果用户名和密码正确,则应调用下一个场景。 Otherwise an alert is shown. 否则,将显示警报。 But I am unable to figure out how to get the next scene conditionally. 但是我无法弄清楚如何有条件地获得下一个场景。

if ([jsonDict valueForKey:@"success"] && [jsonDict valueForKey:@"redirect"]) {

                    NSLog(@"%@", [jsonDict valueForKey:@"success"]);
                    NSLog(@"%@", [jsonDict valueForKey:@"redirect"]);
                    NSString *redirect = [jsonDict valueForKey:@"redirect"];
                    [self performSegueWithIdentifier:@"next" sender:self];
                }
                else {
                    NSArray *jsonArray = [jsonDict valueForKey:@"errors"];
                    NSString *err = [jsonArray objectAtIndex:0];
                    NSLog(@"%@", err);
                    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Credentials!" message:err delegate:nil cancelButtonTitle:@"OK" otherButtonTitles: nil];
                    [alert show];
                }

Set up a Segue to the next viewcontroller in your storyboard and give that segue a unique identifier. 在情节提要中将Segue设置到下一个视图控制器,并为该Segue提供唯一的标识符。 Then, if username and password are ok, just call 然后,如果用户名和密码正确,请致电

[self performSegueWithIdentifier:@"yourSegueIdentifier" sender:self];

Use below code: 使用以下代码:

- (void)validateLogin{
//code to check username and password are correct
if(correct){
[self performSegueWithIdentifier:@"SignInToNextScreen" sender:self];
}else{
 UIAlertView *myalert = [[UIAlertView alloc]initWithTitle:@"Login Failed" message:@"Invalid Username/Password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];   
   }
 }

// SignInToNextScreen is a segue identifier for manually triggered segue. // SignInToNextScreen是手动触发的Segue的Segue标识符。

Please see the attached screen shot 请参阅所附的屏幕截图 在此处输入图片说明

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

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