Ios 从viewcontroller转到tabbar';以编程方式创建视图
嗨,这是我的故事板,我想从第一视图控制器转到LoggedinViewControllerIos 从viewcontroller转到tabbar';以编程方式创建视图,ios,objective-c,uitabbarcontroller,tabbar,Ios,Objective C,Uitabbarcontroller,Tabbar,嗨,这是我的故事板,我想从第一视图控制器转到LoggedinViewController UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:@"Story_Board_Name" bundle:nil]; UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:@"TABid"]; self.t
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:@"Story_Board_Name" bundle:nil];
UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:@"TABid"];
self.tabBarController.selectedIndex = 0;
[self.navigationController pushViewController:self.tabBarController animated:YES];
我通常使用
[self performSegueWithIdentifier:@"s1" sender:self];
但是,如果我添加了tab bar控制器,这行代码不起作用,我如何修复它?从情节提要中为tab bar控制器指定一个标识符,然后执行类似的操作
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:@"Your_Story_Board_Name" bundle:nil];
TabViewController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:@"TAB_Identifier"];
[self presentViewController:tabBarController animated:YES completion:nil];
希望这对您有所帮助如果您已嵌入导航控制器,则可以使用以下功能
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:@"Story_Board_Name" bundle:nil];
UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:@"TABid"];
self.tabBarController.selectedIndex = 0;
[self.navigationController pushViewController:self.tabBarController animated:YES];
或者试试这个
UIStoryboard *myStoryBoard =[UIStoryboard storyboardWithName:@"Story_Board_Name" bundle:nil];
UITabBarController *tabBarController = [myStoryBoard instantiateViewControllerWithIdentifier:@"TABid"];
self.tabBarController.selectedIndex = 0;
[self performSegueWithIdentifier:@"s1" sender:self];
首先将“tabbarid”赋予故事板中的选项卡
UITabBarController *tabBarController1 = [self.storyboard instantiateViewControllerWithIdentifier:@"tabbarid"];
tabBarController1.selectedIndex = 1;
[self presentViewController:tabBarController1 animated:YES completion:nil];
如果
LogedViewController
嵌入了UINavigationController
,该怎么办?在这种情况下,上层代码不起作用。在我使用此代码的场景中,它会将我带到UITabbarController
,但不能通过按它们转到其他选项卡。看起来冷极了。我的解决方案是什么?谢谢