I am trying to use a tabbar to navigate to other view controllers using Xibs. However, I am not able to find tangible resources to proceed further. My current solution involves mapping and I cannot seem to see where the problem is.
import UIKit
class BottomNavViewController: UIViewController {
@IBOutlet weak var home: UITabBarItem!
@IBOutlet weak var assets: UITabBarItem!
@IBOutlet weak var transactions: UITabBarItem!
@IBOutlet weak var profile: UITabBarItem!
@IBOutlet weak var tabBar: UITabBar!
override func viewDidLoad() {
super.viewDidLoad()
navigateTab()
}
func navigateTab() -> Void{
let tabBarController = UITabBarController()
let homeVC = HomeViewController()
let assetsVC = AssetsViewController()
let transactionsVC = TransactionsViewController()
let profileVC = ProfileViewController()
let controllers = [homeVC, assetsVC, transactionsVC, profileVC]
tabBarController.viewControllers = controllers.map {
UINavigationController(rootViewController: $0)
}
}
}
Simply it is like this, You want use UITabbarController
class MYTabViewController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
}
override func viewWillAppear(_ animated: Bool) {
let firstVC = FirstVC()
firstVC.tabBarItem = UITabBarItem(title: "Tab 1", image:(your image), tag: 0)
let secondVC = SecondVC()
secondVC.tabBarItem = UITabBarItem(title: "Tab 2", image: (your image), tag: 1)
viewControllers = [firstVC,secondVC]
}
}