Iphone 切换控制器时选项卡栏消失

Iphone 切换控制器时选项卡栏消失,iphone,ios,xcode,object,tabbar,Iphone,Ios,Xcode,Object,Tabbar,此代码可完美切换视图控制器,但选项卡栏控制器消失。 现在,我尝试了此代码的许多不同变体 [self-presentViewController:homeNavigationController动画:未完成:无] 但它们似乎都不能正常工作。推送控制器只是将视图冻结到位。有什么建议吗 - (void)_tabBarItemClicked:(id)item { assert([item isKindOfClass:[UIButton class]]); NSInteger selecte

此代码可完美切换视图控制器,但选项卡栏控制器消失。
现在,我尝试了此代码的许多不同变体

[self-presentViewController:homeNavigationController动画:未完成:无]

但它们似乎都不能正常工作。推送控制器只是将视图冻结到位。有什么建议吗

 - (void)_tabBarItemClicked:(id)item {   
assert([item isKindOfClass:[UIButton class]]);



NSInteger selectedIndex = ((UIButton *)item).tag;

[self setSelectedIndex:selectedIndex];

[self _setSelectedItemAtIndex:selectedIndex];



NSDictionary *userInfo = @{@"index": [NSNumber numberWithInt:selectedIndex]};

[[NSNotificationCenter defaultCenter] postNotificationName:@"tabBarDidSelectItem" object:nil userInfo:userInfo];
if (selectedIndex ==2) {

    HomeViewController *homeViewController = [[HomeViewController alloc] initWithNibName:nil bundle:nil];
    UINavigationController *homeNavigationController = [[UINavigationController alloc] initWithRootViewController:homeViewController];

    [self presentViewController:homeNavigationController animated:NO completion:nil];

}}

您以模态方式呈现homeNavigationController--您看到的是模态视图控制器的正常行为,也就是说,它们占据整个屏幕,包括选项卡栏。如果要查看选项卡栏,请不要使用模式演示。

我通过以下方法解决了此问题:

1) 在AppDelegate中定义您的TabbarController对象

2) 并从TabbarController的对象中呈现ViewController,而不是像“self”一样

[appDelegateObj.yourTabBarObj presentViewController:homeNavigationController animated:NO completion:nil];];

确保您的Appdelegate对象已初始化。

好的,显示视图控制器的最佳方式是什么。推“因为我试过了,但会引起问题。”费利克斯·琼斯,这完全取决于你想做什么。如果不了解更多有关应用程序结构的信息,以及您试图实现的目标,我真的无法为您提供建议。[self.navigationController pushViewController:homeNavigationController动画:否];我尝试了这个方法,但什么也没发生。@FelixJones,如果不知道你的应用程序结构,这对我来说毫无意义。那个代码在哪个控制器中?您需要编辑您的问题,以显示您在何处拥有哪些控制器以及您正在尝试执行的操作。您已经询问了与选项卡栏相关的各种问题,所有这些问题似乎都表明您对UITabBarController缺乏了解。也许你会很乐意阅读关于它的文档:而且,苹果甚至提供了一个“旨在展示如何构建基于tab栏的iOS应用程序的应用程序”,Tabster:希望你理解,如果不让我知道,我会发布详细的代码。