Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UIButton+Badge only updates badgeValue after view has changed #5

Open
basdvries opened this issue Dec 16, 2014 · 1 comment
Open

UIButton+Badge only updates badgeValue after view has changed #5

basdvries opened this issue Dec 16, 2014 · 1 comment

Comments

@basdvries
Copy link

I've got a (custom) uibutton as a barbuttonitem, and whenever I call .badgeValue or setBadgeValue it only gets updated after the view is reloaded (viewwillappear called)

@mnearents
Copy link

This is old, but leaving this for anyone else that may run into this issue. If you're updating the badge from the appDelegate, you can do the following. My app uses a UITabBarController with UINavigationControllers in each tab, and a UITableViewController or UIViewController in each UINavigationController.

NSInteger count = ...;

//get the root view controller
UITabBarController *tabBar = (UITabBarController*)self.window.rootViewController;

//get the navigation controller
UINavigationController *nvc = (UINavigationController*)tabBar.selectedViewController;

//get the view controller
UITableViewController *table = [nvc.childViewControllers objectAtIndex:0];

//update the badge
table.navigationItem.leftBarButtonItem.badgeValue = [NSString stringWithFormat:@"%li", (long)count];

All of this goes into my didReceiveRemoteNotification method so it triggers whenever a notification is received.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants