UITabBarController退出并重新登录时会扭曲导航栏

时间:2018-11-29 04:13:25

标签: xcode navbar tabbar

我正在创建一个社交媒体类型的应用程序,允许用户登录。登录后,我希望用户进入主页,该页面的底部为TabBarController,顶部为导航栏。我以编程方式创建了TabBar,并将其设置为我的应用程序委托中的rootviewcontroller。构建我的应用程序时,它运行良好,并在顶部显示选项卡栏和导航栏的视图控制器。 This is how my view is supposed to look when I sign out and back in.

但是,如果我要注销然后重新登录,它会通过使导航栏消失并向下推我的搜索栏来扭曲视图。When I log out and back in

我将留下图片进行解释。我尝试将登录控制器navcontrollers更改为

   let mainController = UINavigationController(rootViewController: CustomTabBarController())

        self.present(mainController, animated: true, completion: nil)

 let mainController = UINavigationController(rootViewController: mainViewController())

        self.present(mainController, animated: true, completion: nil)

当我进行此更改时,tabBar控制器消失。 tabbar disappears

我的主视图控制器设置为UIViewController,而我的TabBarCode如下。

class CustomTabBarController: UITabBarController {


override func viewDidLoad() {
    super.viewDidLoad()



    self.tabBar.barTintColor = GREEN_Theme
    self.tabBar.isTranslucent = true
    self.tabBar.tintColor = .white

    let mainController = UINavigationController(rootViewController: mainViewController())
    mainController.tabBarItem.title = "Odd Jobs"
    mainController.tabBarItem.image = UIImage(named: "job-search")
    let settingsController = UINavigationController(rootViewController: SettingsViewController())
    settingsController.tabBarItem.title = "Settings"
    settingsController.tabBarItem.image = UIImage(named: "settings")
    let notificationsController = UINavigationController(rootViewController: notificationsViewController())
    notificationsController.tabBarItem.title = "Notifications"
    notificationsController.tabBarItem.image = UIImage(named: "notification")
    let messagesController = UINavigationController(rootViewController: MessagesController())
    messagesController.tabBarItem.title = "Messages"
    messagesController.tabBarItem.image = UIImage(named: "chat")
    let historyController = UINavigationController(rootViewController: jobhistoryViewController())
    historyController.tabBarItem.title = "Job History"
    historyController.tabBarItem.image = UIImage(named: "history")


    viewControllers = [historyController, notificationsController, mainController, messagesController, settingsController]
    self.selectedIndex = 2
    return

}

我的目标是让用户登录并查看带有导航栏的标签栏。 有什么我缺少的东西或者没有正确实现吗?

0 个答案:

没有答案