1
@interface TopBarController : UIViewController <AVAudioPlayerDelegate, UIAlertViewDelegate> {

UILabel *coinWatch;   }
@property (nonatomic,retain) UILabel *coinWatch;






- (UIView *)coinsLabel {
UIView *coinsLabelView=[[UIView alloc]initWithFrame:CGRectMake(36, 17, 100, 15)];
//if (coinsLabelView == nil) {
    coinWatch = [[UILabel alloc]initWithFrame:CGRectMake(3, 0, 100, 15)];
    coinWatch.font = [self coinsFont];
    coinWatch.textColor = [UIColor colorWithRed:1.0 green:0.83 blue:0.16 alpha:1];
    coinWatch.text = [NSString stringWithFormat:@"%d",  data.getCoins];
    NSLog(@"label %d",data.getCoins);
    coinWatch.backgroundColor = [UIColor clearColor];
//}

[coinsLabelView addSubview:coinWatch];
return coinsLabelView;

}

- (void) setCoin {

[coinWatch performSelectorOnMainThread:@selector(setText:) withObject:[NSString stringWithFormat:@"%d",  data.getCoins] waitUntilDone:NO];
NSLog(@"coin %d",data.getCoins);
NSLog(@"Really updating");

}

我是 xcode 的新手,但这是我用于更新 coinWatch(UILabel) 的简单代码。标签最初为 0,但当我使用其他函数(此处未显示)添加硬币时,NSLog 打印正确的数量但不会更新...当我调用 setCoin 时,它不会更新 coinWatch 中的文本看法。请帮助这个可怜的新手!!!

4

0 回答 0