Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't access TabBarController from ImageView

Tags:

ios

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.

like image 569
Bob Avatar asked Jan 17 '26 20:01

Bob


1 Answers

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";
like image 81
rdelmar Avatar answered Jan 19 '26 18:01

rdelmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!