我正在使用Xcode 7 IOS 9(objective-c)编写一个小IOS应用程序。现在我正试图通过按下名为“确认”的按钮从主故事板切换到第二个故事板。如何在ViewController.m中编写代码以有条件地转到第二个故事板?因此,如果所有输入都正确,用户按下确认它将转到新故事板,否则保持并显示警告消息。谢谢!
答案 0 :(得分:1)
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];
希望有所帮助......
答案 1 :(得分:0)
试试这段代码。可以帮到你。
//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];
}
}