【问题标题】:Tab bar disappearing when switching controller切换控制器时标签栏消失
【发布时间】:2013-03-20 18:22:41
【问题描述】:

这段代码可以完美地切换视图控制器,除了标签栏控制器消失了。
现在我尝试了这段代码的许多不同变体

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

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

 - (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];

}}

【问题讨论】:

标签: iphone ios xcode object tabbar


【解决方案1】:

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

【讨论】:

  • 好的,展示视图控制器的最佳方式是什么。推?因为我尝试过但会导致问题。
  • @FelixJones,这完全取决于您要做什么。如果不详细了解您的应用程序的结构以及您要完成的工作,我真的无法为您提供建议。
  • [self.navigationController pushViewController:homeNavigationController animated:NO];我尝试了这种方法,但没有任何反应。
  • @FelixJones,如果不知道您的应用程序结构,这对我来说毫无意义。该代码在哪个控制器中?您需要编辑您的问题以显示您在哪里拥有哪些控制器,以及您正在尝试做什么。
【解决方案2】:

我通过以下方式解决了这个问题:

1) 在 AppDelegate 中定义 YourTabBarController 对象

2) 和来自 YourTabBarController 的对象的 presentViewController 而不是像 'self' 这样的

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

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

【讨论】:

  • 希望你理解,如果不让我知道我会发布详细的代码。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-04-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-09-08
  • 2016-06-25
相关资源
最近更新 更多