如何有条件地更改为新的故事板

How conditionally change to a new storyboard

我正在使用 Xcode 7 IOS 9 (objective-c) 编写一个 IOS 小应用程序。现在我正试图通过按下一个名为 "confirm" 的按钮从主故事板切换到第二个故事板。我如何在 ViewController.m 中编写代码以有条件地转到第二个故事板?因此,如果所有输入都是正确的,用户按下确认,它将转到新的故事板,否则停留并显示警告消息。谢谢!

    UIStoryboard *storyBoard;
    if (yourcondition)
           storyBoard = [UIStoryboard storyboardWithName:@"StoryBoard1" bundle:[NSBundle mainBundle]];
    else
            storyBoard = [UIStoryboard storyboardWithName:@"StoryBoard2" bundle:[NSBundle mainBundle]];

    YourTargetViewController *targetCon = [stryBoard instantiateViewControllerWithIdentifier:@"TargetControllerID"];
    [self.navigationController pushViewController:targetCon animated:YES];

希望对您有所帮助..

试试这个代码。可能对你有帮助。

//button Actions
- (IBAction)loginbtnClicked:(id)sender
{
    [self.tfEmail resignFirstResponder];
    [self.tfPasswrd resignFirstResponder];
    if ([self.tfEmail.text isEqualToString:@""] || [self.tfPasswrd.text isEqualToString:@""])
    {
          UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@“Title” message:@"You are required to fill out all fields." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
          [alert show];
          return;
    }
   if ([self isEmailValid:self.tfEmail.text])
   {
         //put your required code here.

        //Navigate to next view controller.
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main” bundle:nil];
        HomeVC *homeVC =[storyboard instantiateViewControllerWithIdentifier:@"HomeVCID"];
        [self.navigationController pushViewController:chatVC animated:TRUE];
   }
   else
   {
         UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@“Title” message:@"Please enter valid email address." delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
   }
}