首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何有条件地改变成一个新的故事板

如何有条件地改变成一个新的故事板
EN

Stack Overflow用户
提问于 2015-09-25 05:45:30
回答 2查看 47关注 0票数 0

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

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2015-09-25 05:52:54

代码语言:javascript
复制
    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
EN

Stack Overflow用户

发布于 2015-09-25 06:01:43

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

代码语言:javascript
复制
//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];
   }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32775596

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档