首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TabBar控制NavigationBar

TabBar控制NavigationBar
EN

Stack Overflow用户
提问于 2019-05-11 21:53:21
回答 2查看 27关注 0票数 0

我在TabBar中添加了2个ViewControllers,但是现在,标签栏的NavigationBar“接管”了每个视图的NavigationBar。我不能为它们每一个设置一个标题,我不能添加按钮,什么都不能。我尝试了一些解决方案,我在互联网上找到了解决方案,但都没有奏效。我需要控制每个视图的NavigationBar,因为我需要它们是不同的,具有不同的标题等。这是我的TabBar代码:

代码语言:javascript
复制
class TabBar: UITabBarController {
let homeVC = HomeVC()
let followingVC = FollowingVC()

override func viewDidLoad() {
    super.viewDidLoad()
    navigationController?.navigationBar.titleTextAttributes = [.foregroundColor: UIColor.appColors.mainWhite]
    navigationController?.navigationBar.tintColor = UIColor.appColors.mainWhite
    navigationItem.setHidesBackButton(true, animated: false)

    homeVC.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 0)
    followingVC.tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: 1)

    let tabBarList = [homeVC, followingVC]
    viewControllers = tabBarList
}
}

我真的需要从自己的ViewController配置每个NavigationBar的选项,或者至少从TabBar类配置。

EN

回答 2

Stack Overflow用户

发布于 2019-05-11 22:36:20

您应该将UINavigationController添加到每个ViewControllers中,而不是UITabBarController

首先删除你的TabBar的UINavigationController,要么你已经实际地这样做了,要么在故事板中先删除它。

第二,向你的ViewControllers添加UINavigationController

代码语言:javascript
复制
class TabBar: UITabBarController {

  let homeVC = HomeVC()
  let followingVC = FollowingVC()

  override func viewDidLoad() {
    super.viewDidLoad()

    homeVC.tabBarItem = UITabBarItem(tabBarSystemItem: .topRated, tag: 0)
    followingVC.tabBarItem = UITabBarItem(tabBarSystemItem: .contacts, tag: 1)

    let homeNavigationController = UINavigationController(rootViewController: homeVC)
    let followingNavigationController = UINavigationController(rootViewController: followingVC)


    let tabBarList = [homeNavigationController, followingNavigationController]
    viewControllers = tabBarList
  }
}

现在,如果您更改任何属性,如title和barButtons,它将相应地反映出来。

票数 0
EN

Stack Overflow用户

发布于 2019-05-12 00:38:56

想清楚了,解决方案是: navigationbar不是TabBar导航栏,而是通向TabBar的屏幕(例如登录屏幕),我通过在转移到TabBar控制器时隐藏登录屏幕的导航栏来修复这个问题,现在每个视图控制器的导航栏都会显示出来,并且不会被登录视图控件的导航栏阻挡。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/56090974

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档