Refresh / Refresh tab bar items in ViewController?

I am trying to change the images of my tab in the ViewController, but in order to display new images I have to click on each element of the tab bar.

for (CustomTabBarItem *myItem in self.tabBarController.tabBar.items){
        myItem.enabled = YES; 

        myItem.badgeValue = @"1"; 

        UIImage *myImage =  [[UIImage alloc] initWithContentsOfFile:[[DesignManager sharedManager] getPathOfFile:@"test.png"]];

        *myItem.imageSelect= *myImage; // change images of each item. don't appear if I dont click on the item
}

Does anyone know How can I display these images directly? Thanks

+3
source share
2 answers

You need to replace the old tab bar item with a new one. You cannot update the image dynamically otherwise.

The easiest way to do this is to set the tabBarItem property of the view controller represented by this tab. If you want to do this from within this controller, simply write:

self.tabBarItem = [[UITabBarItem alloc] initWithTitle: @"title" image: myImage: tag: nil];

, , :

UIViewController* vc = [tabBarController.viewControllers objectAtIndex: 3];
vc.tabBarItem = [[UITabBarItem alloc] initWithTitle: @"title" image: myImage: tag: nil];
+2

, . , . UITabBarItem , , . , , UITabBarItem.

vc.tabBarItem = vc.tabBarItem; 

.

+2

Source: https://habr.com/ru/post/1775657/


All Articles