Reputation: 17651
I have the following method which adds a MKNumberBadgeView
to the UINavigationBar
of a UITableViewController
-
-(void)counterBtn{
MKNumberBadgeView *numberBadge = [[MKNumberBadgeView alloc] initWithFrame:CGRectMake(25, -10, 40, 40)];
numberBadge.strokeColor = [UIColor colorWithRed:239.0/255.0 green:117.0/255.0 blue:33/255.0 alpha:0];
numberBadge.fillColor = [UIColor colorWithRed:239.0/255.0 green:117.0/255.0 blue:33/255.0 alpha:1];
numberBadge.shine = NO;
numberBadge.hideWhenZero = YES;
numberBadge.value = _countBtnNo;
NSLog(@"Value of count = %d", _countBtnNo);
[self.navigationController.navigationBar addSubview:numberBadge];
}
All works fine until I want to change the count value - I have the following function to change the value -
- (void)removeBtn{
NSLog(@"ddd");
_countBtnNo = 0;
[self counterBtn];
}
But this does nothing - So i'm guessing I need to remove the subview first before re-adding - though there doesnt seem to be a removeSubview:numberBadge
method - so i'm struggling!
Upvotes: 1
Views: 49
Reputation: 40030
Store a reference to your numberBadge
in a property:
@property(nonatomic, strong) MKNumberBadgeView *numberBadge;
Then initialize it. To remove it, just call
[_numberBadge removeFromSuperview];
Alternatively you can just update the value of the counter. No need to remove it.
_numberBadge.value = new value;
Upvotes: 1