How to reload UIBarButtonItem in IOS

My app looks like a shopping cart. I have added one cart UIBarButtonItem to the navbar.
In the cart, I added an icon at the top.
Now my question is when I add an item to the cart. How do I update the icon on a button without navigation or when I remove an item from the trash icon there will be an update.
Is it possible to reload the navbar without navigation?

+3


source to share


2 answers


I just update my icon when I want to reload. Ex. when i remove any item from the cart i reinitialize the panel button element. Here is my code:



 NSMutableArray *arrProducts = [[notification userInfo] objectForKey:@"CartList"];

[[NSUserDefaults standardUserDefaults] setInteger:[arrProducts count] forKey:@"Badge"];
[[NSUserDefaults standardUserDefaults] synchronize];

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *backButtonImage = [UIImage imageNamed:@"shopping_cart.png"];
[button setBackgroundImage:backButtonImage forState:UIControlStateNormal];
// add badge to cart button.
[CommonUtils AddBadge:button];
[button addTarget:self action:@selector(AddToCartClicked:) forControlEvents:UIControlEventTouchUpInside];
button.frame = CGRectMake(0, 0, 30, 30);

[btnAddtoCart initWithCustomView:button];

      

+1


source


Check the status and show / hide the icon respectively.

First, you need to hide the icon. When any item is selected, the check for the selected item count is greater than 0 and then the icon is displayed.



Each time the selected item displays an icon.

Every time any item is canceled, check if the selected item is selected == 0, then hide the icon.

0


source







All Articles