I have an app that has a navigation controller in a tabbar controller. The root for the navigation controller is a table view controller. The table view has a segue to an image view. I want to update the badge value on a tab from the image view controller. From the tabbar controller, this works fine:
UIViewController *viewController = [self.tabBarController.viewControllers objectAtIndex:1];
viewController.tabBarItem.badgeValue = @"x";
But when I put the same code into the imageview controller, it doesn't work. When I check the value of 'viewController' after it executes, the value is nil. Same for self.tabBarController. For some reason the image view controller can't see its tabbarcontroller.
You should be able to access the tabBarController with self.navigationController.tabBarController. So your code needs to be:
UIViewController *viewController = [self.navigationController.tabBarController.viewControllers objectAtIndex:1];
viewController.tabBarItem.badgeValue = @"x";
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With