I am having a hard time understanding the following issue:
This code does what i think it should do: Initialize badges, move it after the initialization and update label on the badge:
- Initialize badge
- Set value to 24 (or some other number)
- Add UIView on screen
- Change UIView location
- Change value to read xx
[self initializeCardBadges]; [gameView addSubview:unplayedCountBadge]; [unplayedCountBadge setFrame:CGRectMake(315, 5, 25, 25)]; // Moves unplayedCountBadge.badgeText = @"xx"; // Updates label
where initializeCardBadges does the following:
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)];
Once the badge is in place, we are free to move it around and change text. As mentioned above this works.
When i add a new method to update the badge labels, as expected, all is well again
[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";
}
But .. when i add the same logic to -(IBAction) doneWithThisRoundDealCards:(id)sender, upon button tap ..
[unplayedCountBadge setFrame:CGRectMake(315, 5, 25, 25)]; // Moves
[self updateBadgeLabelForUnplayedCards]; // Value NOT set
Additionally, when i replace the above with explicit commands, the same can be observed: badge moves location, value is not set
[unplayedCountBadge setFrame:CGRectMake(315, 5, 25, 25)]; // Moves
self.unplayedCountBadge.badgeText=@"tt"; // Value NOT set
Badge location changes, but … text does not update. Why is this?
I am reusing this code for badge generation.
Note that BadgeText is defined as a simple property, as shown here
@property(nonatomic,retain) NSString *badgeText;
did you try
?