Ios 徽章不';t显示值
我有一个巴布顿徽章。 我想在其中显示一个整数Ios 徽章不';t显示值,ios,uibutton,nsstring,nsinteger,Ios,Uibutton,Nsstring,Nsinteger,我有一个巴布顿徽章。 我想在其中显示一个整数 @property (nonatomic) int section; @synthesize section; -(void)sendBadgeIntBack:(int)section { self.section = section; NSLog(@"The numbers of sections in tableView are: %i", self.section); } NSString *strValue = [
@property (nonatomic) int section;
@synthesize section;
-(void)sendBadgeIntBack:(int)section
{
self.section = section;
NSLog(@"The numbers of sections in tableView are: %i", self.section);
}
NSString *strValue = [@(section) stringValue];
BBBadgeBarButtonItem *barButton = [[BBBadgeBarButtonItem alloc] initWithCustomUIButton:customButton];
barButton.badgeValue = strValue;
在NSLog中,我得到了一个正确的值
我还尝试了其他一些方法:
NSString *strValue = [NSString stringWithFormat:@"%d", section];
NSString *strValue = [NSString stringWithFormat:@"%i", section];
barButton.badgeValue = [NSString stringWithFormat:@"%d", section];
有没有什么原因使它不起作用
编辑:
UIButton *customButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 20, 20)];
[customButton addTarget:self action:@selector(barButtonItemPressed:) forControlEvents:UIControlEventTouchUpInside];
[customButton setImage:[UIImage imageNamed:@"afvaldag"] forState:UIControlStateNormal];
什么是
customButton
?这可能是它失败的原因吗?此外,BBBadgeBarbuttonite似乎是一个自定义类。来源是什么?自定义按钮是UIButton。请参阅更新。第二,来源是这里:如果您登录badgeButton.badgeValue
,您会得到什么?何时设置badgeButton
?当我记录badgeButton.badgeValue时,我得到0。我在ViewDidLoad中设置了badgeButton。在尝试将其转换为NSString
之前,请尝试记录部分。我认为您的架构有问题。