我正在用Xcode 7 IOS 9编写一个小IOS应用程序(目标-c)。现在,我正试图通过按一个名为“确认”的按钮,从主故事板切换到第二个故事板。如何在ViewController.m中编写有条件地转到第二个故事板的代码?因此,如果所有输入是正确的,用户按确认它将转到新的故事板,否则停留和显示警告信息。谢谢!
发布于 2015-09-25 05:52:54
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];希望能帮上忙..。
发布于 2015-09-25 06:01:43
试试这段代码。可能对你有帮助。
//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];
}
}https://stackoverflow.com/questions/32775596
复制相似问题