删除UINavigationBarButton SubView

时间:2014-04-04 16:24:39

标签: ios objective-c

我有以下方法将MKNumberBadgeView添加到UINavigationBar的{​​{1}} -

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];

但这没有任何作用 - 所以我猜我需要先重新添加子视图才能重新添加 - 虽然似乎没有- (void)removeBtn{ NSLog(@"ddd"); _countBtnNo = 0; [self counterBtn]; } 方法 - 所以我很难挣扎!

1 个答案:

答案 0 :(得分:1)

  1. numberBadge的引用存储在属性中:

    @property(nonatomic, strong) MKNumberBadgeView *numberBadge;
    
  2. 然后初始化它。要删除它,只需调用

    [_numberBadge removeFromSuperview];
    
  3. 或者您可以更新计数器的值。无需删除它。

    _numberBadge.value = new value;