我很难理解以下问题:
此代码执行我认为应该执行的操作:初始化徽章,在初始化后移动徽章并更新徽章上的标签:
[self initializeCardBadges]; [gameView addSubview:unplayedCountBadge]; [unplayedCountBadge setFrame:CGRectMake(315, 5, 25, 25)]; // Moves unplayedCountBadge.badgeText = @"xx"; // Updates label
initializeCardBadges
执行以下操作:
self.unplayedCountBadge = [CustomBadge customBadgeWithString:[NSString stringWithFormat:@"%d", decks.masterDeck.count]
withStringColor:[UIColor whiteColor]
withInsetColor:[UIColor redColor]
withBadgeFrame:YES
withBadgeFrameColor:[UIColor whiteColor]
withScale:1.0
withShining:YES];
[self.unplayedCountBadge setFrame:CGRectMake(435, 5, 25, 25)];
徽章到位后,我们可以自由移动徽章并更改文字。如上所述,这有效。
当我添加新方法来更新徽章标签时,正如预期的那样,一切都很好
[self initializeCardBadges];
[gameView addSubview:unplayedCountBadge];
[unplayedCountBadge setFrame:CGRectMake(315, 5, 25, 25)]; // Moves badge to location
[self updateBadgeLabelForUnplayedCards]; // Updates label
-(void) updateBadgeLabelForUnplayedCards {
unplayedCountBadge.badgeText=@"yy";
}
但..当我向-(IBAction) doneWithThisRoundDealCards:(id)sender
添加相同的逻辑时,按下按钮...
[unplayedCountBadge setFrame:CGRectMake(315, 5, 25, 25)]; // Moves
[self updateBadgeLabelForUnplayedCards]; // Value NOT set
此外,当我用显式命令替换上面的内容时,可以观察到相同的情况:徽章移动位置,值未设置
[unplayedCountBadge setFrame:CGRectMake(315, 5, 25, 25)]; // Moves
self.unplayedCountBadge.badgeText=@"tt"; // Value NOT set
徽章位置更改,但...文本未更新。这是为什么?
我正在重复使用此code来生成徽章。
请注意,BadgeText被定义为一个简单属性,如here
所示@property(nonatomic,retain) NSString *badgeText;
答案 0 :(得分:3)
[unplayedCountBadge setNeedsDisplay];
答案 1 :(得分:3)
我不知道为什么你没有使用- (void) autoBadgeSizeWithString:(NSString *)badgeString
方法更改徽章文字,但我在该方法中看到的一件事就是它调用了[self setNeedsDisplay]
你似乎没有