我有控制器:
@interface BallsViewController ()
@property (weak, nonatomic) IBOutlet UILabel *label;
@end
@implementation BallsViewController
@synthesize viewBoard;
- (id)initWithNibName:(NSString *)nibName bundle:(NSBundle *)nibBundle
{
self = [super initWithNibName:nibName bundle:nibBundle];
if (self)
{
// ScoreLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 200, 300, 30)];
// [self.view addSubview:ScoreLabel];
// add other stuff you need to initialize ...
}
return self;
}
- (id)init
{
// since we don't wanna re-implement allocation and instantiation for every
// initializer, we call the 'designated initializer' with some default values,
// in this case the default nibName and bundle are nil.
return [self initWithNibName:nil bundle:nil];
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self.viewBoard Draw:@"Fields"];
// Do any additional setup after loading the view, typically from a nib.
self.label.text = @"lll";
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)NewGame:(id)sender {
self.label.text = @"aaa";
self.viewBoard.canDrawBall = true;
[self.viewBoard Draw:@"Fields"];
// }
// else
// {
// self.InfoLabel.text = @"End game";
// }
}
-(void)UpdateScore:(int)score
{
NSLog(@"%@", self.label);
NSString *scoreStr =[NSString stringWithFormat:@"%d",score];
[self.label setText:scoreStr];
}
@end
当我在 viewDidLoad 中检查标签并初始化 NewGame 方法控件时,我可以为标签设置新值。但是当我调用委托方法UpdateScore时,我的标签是空的,即使我在上面提到的调用方法之后执行这个方法。为什么会发生?如何解决这个问题?