I have two views A & B in order to go from A to B I'm just pushing the new view, in view B I preform some actions that update the badgeValue of a UIBarButton item of my navigation bar. (Like adding an item to the shopping cart)
When I go back to view A using the navigationBar Back button the UIBarButton item shows the previous badgeValue, instead of the updated one, I guess this happens because when you press the back button view B is popped revealing view A which is left as it was without any changes so, I need a way to tell view A to update itself after returning.
If instead of going back to view A I go back to the rootViewController the badgeValue is updated, I guess that when I go to the rootViewController the code in viewDidLoad is read and the badgeValue is updated.
Any ideas on how to update a view that was behind another that was just popped?
EDIT
@silicon_valley answer is correct but it won't work with MikeMTOL's library because it's buggy, for Swift users I'd recommend these extensions instead. -> link
You can add your code to update the badge value in viewWillAppear
. That will make sure the value is updated every time the view will come back on the screen (and not just the first time it is created).