添加 tabBarController 后导航消失,iOS,Swift
Navigation disappeared after adding tabBarController, iOS, Swift
我正在尝试实现 tabBarController 并且我设法做到了,但是现在我在 tabBar 内的屏幕上的导航消失了。我尝试在 viewDidLoad 中的每个 viewController 中将 isHidden 设置为 false,但没有帮助。下面的代码来自我的 tabBarController。
class BottomTabBarViewController: UITabBarController, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = false
self.viewControllers = [bookedTrips, bookedTripsDetails, needHelp]
customizeTabBar()
}
func customizeTabBar() {
tabBar.backgroundColor = .init(red: 0.949, green: 0.949, blue: 0.949, alpha: 1)
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
tabBar.tintColor = .init(red: 0.949, green: 0.392, blue: 0.153, alpha: 1)
tabBar.unselectedItemTintColor = .init(red: 0.753, green: 0.753, blue: 0.753, alpha: 1)
}
lazy public var bookedTrips: BookedTripsListViewController = {
let initialTabBar = BookedTripsListViewController(networkManager: NetworkManager())
let tabBarItems = UITabBarItem(title: "First", image: UIImage(named: "bag.png"), selectedImage: UIImage(named: "bag.png"))
let tabBarItem = UITabBarItem(title: tabBarItems.title, image: tabBarItems.image, selectedImage: tabBarItems.selectedImage)
initialTabBar.tabBarItem = tabBarItem
return initialTabBar
}()
lazy public var bookedTripsDetails: TripDetailsViewController = {
let initialTabBar = TripDetailsViewController()
let tabBarItems = UITabBarItem(title: "Second", image: UIImage(named: "bag.png"), selectedImage: UIImage(named: "bag.png"))
let tabBarItem = UITabBarItem(title: tabBarItems.title, image: tabBarItems.image, selectedImage: tabBarItems.selectedImage)
initialTabBar.tabBarItem = tabBarItem
return initialTabBar
}()
lazy public var needHelp: NeedHelpViewController = {
let initialTabBar = NeedHelpViewController()
let tabBarItems = UITabBarItem(title: "Third", image: UIImage(named: "bag.png"), selectedImage: UIImage(named: "bag.png"))
let tabBarItem = UITabBarItem(title: tabBarItems.title, image: tabBarItems.image, selectedImage: tabBarItems.selectedImage)
initialTabBar.tabBarItem = tabBarItem
return initialTabBar
}()
}
不确定是否相关,但我将 tabBar 设置为在登录后可见,因此如果登录数据正确,则显示 tabBar。
设法解决了这个问题,如果有人需要与此类似的帮助,解决方案是设置 return type UINaviagtionController 并将 viewController 的实例设置为 rootController,示例如下。
lazy public var bookedTrips: UINavigationController = {
let initialTabBar = UINavigationController(rootViewController: BookedTripsListViewController(networkManager: NetworkManager()))
let tabBarItems = UITabBarItem(title: "First", image: UIImage(named: "bag.png"), selectedImage: UIImage(named: "bag.png"))
let tabBarItem = UITabBarItem(title: tabBarItems.title, image: tabBarItems.image, selectedImage: tabBarItems.selectedImage)
initialTabBar.tabBarItem = tabBarItem
return initialTabBar
}()
我正在尝试实现 tabBarController 并且我设法做到了,但是现在我在 tabBar 内的屏幕上的导航消失了。我尝试在 viewDidLoad 中的每个 viewController 中将 isHidden 设置为 false,但没有帮助。下面的代码来自我的 tabBarController。
class BottomTabBarViewController: UITabBarController, UINavigationControllerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
self.navigationController?.isNavigationBarHidden = false
self.viewControllers = [bookedTrips, bookedTripsDetails, needHelp]
customizeTabBar()
}
func customizeTabBar() {
tabBar.backgroundColor = .init(red: 0.949, green: 0.949, blue: 0.949, alpha: 1)
tabBar.shadowImage = UIImage()
tabBar.backgroundImage = UIImage()
tabBar.tintColor = .init(red: 0.949, green: 0.392, blue: 0.153, alpha: 1)
tabBar.unselectedItemTintColor = .init(red: 0.753, green: 0.753, blue: 0.753, alpha: 1)
}
lazy public var bookedTrips: BookedTripsListViewController = {
let initialTabBar = BookedTripsListViewController(networkManager: NetworkManager())
let tabBarItems = UITabBarItem(title: "First", image: UIImage(named: "bag.png"), selectedImage: UIImage(named: "bag.png"))
let tabBarItem = UITabBarItem(title: tabBarItems.title, image: tabBarItems.image, selectedImage: tabBarItems.selectedImage)
initialTabBar.tabBarItem = tabBarItem
return initialTabBar
}()
lazy public var bookedTripsDetails: TripDetailsViewController = {
let initialTabBar = TripDetailsViewController()
let tabBarItems = UITabBarItem(title: "Second", image: UIImage(named: "bag.png"), selectedImage: UIImage(named: "bag.png"))
let tabBarItem = UITabBarItem(title: tabBarItems.title, image: tabBarItems.image, selectedImage: tabBarItems.selectedImage)
initialTabBar.tabBarItem = tabBarItem
return initialTabBar
}()
lazy public var needHelp: NeedHelpViewController = {
let initialTabBar = NeedHelpViewController()
let tabBarItems = UITabBarItem(title: "Third", image: UIImage(named: "bag.png"), selectedImage: UIImage(named: "bag.png"))
let tabBarItem = UITabBarItem(title: tabBarItems.title, image: tabBarItems.image, selectedImage: tabBarItems.selectedImage)
initialTabBar.tabBarItem = tabBarItem
return initialTabBar
}()
}
不确定是否相关,但我将 tabBar 设置为在登录后可见,因此如果登录数据正确,则显示 tabBar。
设法解决了这个问题,如果有人需要与此类似的帮助,解决方案是设置 return type UINaviagtionController 并将 viewController 的实例设置为 rootController,示例如下。
lazy public var bookedTrips: UINavigationController = {
let initialTabBar = UINavigationController(rootViewController: BookedTripsListViewController(networkManager: NetworkManager()))
let tabBarItems = UITabBarItem(title: "First", image: UIImage(named: "bag.png"), selectedImage: UIImage(named: "bag.png"))
let tabBarItem = UITabBarItem(title: tabBarItems.title, image: tabBarItems.image, selectedImage: tabBarItems.selectedImage)
initialTabBar.tabBarItem = tabBarItem
return initialTabBar
}()