I am trying to use customized tab viewController, in which the user can add/re-arrange them the way he/she likes. in the following code I only need to return the array count and display the array items, I managed to do it by a number of the array, but when using it as a single array code, it displays only one view controller!!
here is the code:
class ContainerController: UITabBarController {
override func viewDidLoad() {
super.viewDidLoad()
let selectedViewControllers = [Home(),Index(),Favourite(),Library()]
let selectedViewControllersProperties = ["Home","Index","Favourite","Library"]
viewControllers = [createController(title: "\(selectedViewControllersProperties[0])".localized, imageName: "\(selectedViewControllersProperties[0])", vc: selectedViewControllers[0]),
createController(title: "\(selectedViewControllersProperties[1])", imageName: "\(selectedViewControllersProperties[1])", vc: selectedViewControllers[1]),
createController(title: "\(selectedViewControllersProperties[2])", imageName: "\(selectedViewControllersProperties[2])", vc: selectedViewControllers[2]),
createController(title: "\(selectedViewControllersProperties[3])", imageName: "\(selectedViewControllersProperties[3])", vc: selectedViewControllers[3]),]
}
// MARK: - Handlers
func createController(title: String, imageName: String, vc: UIViewController) -> UINavigationController{
let recentVC = UINavigationController(rootViewController: vc)
recentVC.tabBarItem.title = title
recentVC.tabBarItem.image = UIImage(named: imageName)
return recentVC
}
}
When trying to use this array instead, it shows only ONE viewController:
let tabCount = selectedViewControllersProperties.count - 1
for i in 0...tabCount {
viewControllers = [createController(title: "\(selectedViewControllersProperties[i])".localized, imageName: "\(selectedViewControllersProperties[i])", vc: selectedViewControllers[i])]
}
What I did wrong here, please help me to resolve it.