I am using this control for showing badge on barbuttonitem. It works fine for the first controller or root controller in navigation controller stack. While pushing to another controller, I tried to show badge and I cannot see any effect there.
Asked
Active
Viewed 900 times
3
-
This question is rather brief, and I wonder - whilst not being a iOS dev - whether it does not show readers what you have tried. Would you add the relevant part of your code? – halfer Jan 05 '16 at 12:28
-
Badge is displayed or not in other viewcontroller – HariKrishnan.P Jan 05 '16 at 12:46
-
no badge is not shown in detail view controller – bhumi gajjar Jan 05 '16 at 12:52
-
i am asking about the the badge view. not badge count – HariKrishnan.P Jan 05 '16 at 12:59
-
not badge 'view' is not shown in detail view controller – bhumi gajjar Jan 05 '16 at 13:45
2 Answers
2
You should first time set badgeValue in viewDidLayoutSubviews
. In this case it'll appear and don't blink, like if you set it in viewDidAppear
:
- (void)viewDidLayoutSubviews {
barButton.badgeValue = @"5";
}

Igor
- 12,165
- 4
- 57
- 73
-
I moved `navRightButton = [[UIBarButtonItem alloc] init]; self.navigationItem.rightBarButtonItem = navRightButton; self.navigationItem.rightBarButtonItem.badgeValue = @"1";` to viewDidLayoutSubviews. This solved my problem. – Joeful6 Aug 12 '16 at 09:51
0
Setting navigationItem
in viewDidLayoutSubviews
is not recommended because it is not semantic.
The key to your problem is that the badge view is added to [UIBarButtonItem valueForKey:@"view"]
, but when UIBarButtonItem
is initialized, valueForKey:@"view"
doesn't exist yet, so adding a badge fails.
I suggest you try QMUIBadge, it can solve your problem.
UIBarButtonItem *rightItem = [[UIBarButtonItem alloc] init];
rightItem.qmui_badgeInteger = 1;// number
rightItem.qmui_badgeString = @"99+";// or string
// setRightBarButtonItem any time
self.navigationItem.rightBarButtonItem = rightItem;

MoLice
- 301
- 2
- 7