【问题标题】:putting local tabBar on the global tabBar (I have a global tabBarController)将本地 tabBar 放在全局 tabBar 上(我有一个全局 tabBarController)
【发布时间】:2012-01-12 20:01:58
【问题描述】:

我在我一直在开发的 iphone 应用程序中放置了一个全局 tabBarController。 但是在我的一个屏幕中,我需要放置与全局 tabBarController 不同的本地 tabBar。

我通过两种方式做到了: 1)通过self.tabBarController.tabBar.hidden隐藏全局tabBar = yes;并将本地 tabBar 放置在视图中。但是 tabBar 的框架显示空白。 2) 尝试通过添加本地 tabBar 作为全局 tabBar 的子视图,但在卸载屏幕后,它不会通过应用 [localTabBar removeFromSuperView] 删除本地 tabBar;

提前谢谢..

Global tabBarController:
tabBarController          = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray    arrayWithObjects:ActivityTabnav,nav2,privateChatnav,ExploreTabnav,nav3,tempTabnav, nil];

localtabBar 是 viewController 的 view xib 上的 tabBar。 在 viewDidLoad >

 UIWindow* window = [[UIApplication sharedApplication] keyWindow];
 [window addSubview:self.tabBar];

在viewDidUnLoad中>

[self.tabBar removeFromSuperview];

之前我尝试将 self.tabBar 添加到 self.tabBarController.tabBar 作为一个子视图,它将本地 self.tabBar 保留在其他屏幕中。

谢谢...

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    我发现的最简洁的方法是设置视图控制器的hidesBottomBarWhenPushed 属性,然后将其放置在UINavigationController 中(如果不需要,隐藏导航栏)。这将隐藏UITabBarController's UITabBar 而不会留下空白。

    然后将本地 UITabBar 直接放入 UIViewController's 视图中;

    另一种可能性是隐藏UITabBarController'sUITabBar,然后将本地UITabBar 添加到UITabBarController's 视图的子视图中。当然,您必须在需要时从 superview 中删除。

    【讨论】:

    • 恐怕我做到了。设置 hidesBottomBarWhenPushed 属性有效,但在屏幕卸载后 localTabBar 是持久化,尽管它已从超级视图中删除。我已经将 localtabBar 设置为全局 tabBar 和 tabBarController View 的子视图。
    • 嘿嗨,谢谢大家.. 在 vi​​ewController 的初始化函数中设置 hidesBottomBarWhenPushed 的全局 tabBar 做到了。
    【解决方案2】:

    一种方法是在 Window 上添加 TabBar。但要确保你的处理是正确的。您可以通过获取当前窗口对象将其添加到窗口上,然后将 TabBar 添加到它上面...如下...

    UIWindow* window = [[UIApplication sharedApplication] keyWindow];
    [window addSubview:tabbar];
    

    这可能是一种选择,但要小心处理...

    【讨论】:

    • 它添加了 tabBar,但是当屏幕被卸载时(即 viedDidUnload)[tabBar removeFromSuperview] 没有删除它。这个本地视图被持久化到其他屏幕上。谢谢...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-10
    • 1970-01-01
    • 2014-03-25
    • 2018-06-25
    • 2015-04-01
    • 2021-03-05
    • 1970-01-01
    相关资源
    最近更新 更多