I have a UITabBar with it's own UITabBarController and in this controller I'm doing some adjustments to the tabBar such as disabling/enabling tabBar items. I'm doing it in viewDidLoad.
Trigger for these adjustments however will be on one of the related tabs and it's view controller. The trigger will be a button and once the button is pressed one of the items on the tabBar should go from "disabled" to "enabled".
Is there any tabBar reload function that I need to use or do I need to somehow reload UITabBarController to make this happen?
Thanks - I appreciate any help you can provide!
Edit: My VCs for UITabBarController and UIViewController are below.
UITabBarController
class TabBarVC: UITabBarController, TopRatedVCDelegate {
var tabBarItem1 = UITabBarItem()
var tabBarItem2 = UITabBarItem()
var tabBarItem3 = UITabBarItem()
var tabBarItem4 = UITabBarItem()
override func viewDidLoad() {
super.viewDidLoad()
}
func setbar() {
let tabBarControllerItems = tabBar.items
if let tabArray = tabBarControllerItems {
tabBarItem1 = tabArray[0]
tabBarItem2 = tabArray[1]
tabBarItem3 = tabArray[2]
tabBarItem4 = tabArray[3]
}
tabBarItem1.isEnabled = true
tabBarItem1.badgeValue = "99"
tabBarItem2.isEnabled = false
tabBarItem3.isEnabled = true
tabBarItem4.isEnabled = true
}
}
UIViewController with button
protocol TopRatedVCDelegate: class {
func setbar()
}
class TopRatedVC: UIViewController {
@IBOutlet weak var userDefValueLbl: UILabel!
weak var delegate: TopRatedVCDelegate?
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func btnPressed(_ sender: Any) {
delegate?.setbar()
}
}
trigger button
to "call back" to your customUITabBarController
where you can handle disabling / enabling tabs (or whatever else you want to do). – DonMag