我正在尝试切换回特定索引处的UITabBarController。我的方法似乎不起作用。这是我的代码:
BaseViewController.m
-(void)switchTabView: (NSString*) viewName inx: (int) index
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UITabBarController *view = [storyBoard instantiateViewControllerWithIdentifier:viewName];
view.tabBarController.selectedIndex = index;
[self presentViewController:view animated:YES completion:nil];
}
ChildViewController.m(继承BaseViewController)
- (IBAction)backButtonClicked:(id)sender
{
[self switchTabView:@"tabView" inx:1];
}
它返回到UITabBarController,但索引参数似乎并不重要,因为它总是转到索引0。
答案 0 :(得分:2)
尝试更改
-(void)switchTabView: (NSString*) viewName inx: (int) index
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UITabBarController *view = [storyBoard instantiateViewControllerWithIdentifier:viewName];
view.tabBarController.selectedIndex = index;
[self presentViewController:view animated:YES completion:nil];
}
到
-(void)switchTabView: (NSString*) viewName inx: (int) index
{
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil];
UITabBarController *view = [storyBoard instantiateViewControllerWithIdentifier:viewName];
view.selectedIndex = index;
[self presentViewController:view animated:YES completion:nil];
}