这是我的代码。我希望当计时器达到0时按钮会改变,但它不起作用:
-(void) SwitchView{
[switchingTimer invalidate];
self.SwitchingTimer = nil;
[self bomb:nil];
}
-(IBAction)bomb:(UIButton *)sender {
UIButton *button = (UIButton *)sender;
[button setImage:[UIImage imageNamed:@"black_bomb.png"] forState:UIControlStateNormal];
int xmin = ([button frame].size.width)/2;
int ymin = ([button frame].size.height)/2;
int x = xmin + arc4random_uniform(self.view.frame.size.width - button.frame.size.width);
int y = ymin + arc4random_uniform(self.view.frame.size.height - button.frame.size.height);
[button setCenter:CGPointMake(x, y)];
[self flower:sender];
}
-(IBAction)flower:(UIButton *)sender{
UIButton *button2 = (UIButton *)sender;
[button2 setImage:[UIImage imageNamed:@"red_rose_flower_6.png"] forState:UIControlStateNormal];
int xmin = ([button2 frame].size.width)/2;
int ymin = ([button2 frame].size.height)/2;
int x = xmin + arc4random_uniform(self.view.frame.size.width - button2.frame.size.width);
int y = ymin + arc4random_uniform(self.view.frame.size.height - button2.frame.size.height);
[button2 setCenter:CGPointMake(x, y)];
if (self.switchingTimer == nil) {
self.switchingTimer = [NSTimer scheduledTimerWithTimeInterval:2 target:self selector:@selector(SwitchView) userInfo:nil repeats:YES];
}
答案 0 :(得分:3)
你正在打电话
[self bomb:nil];
发件人nil
。
但bomb
方法使用发件人:
-(IBAction)bomb:(UIButton *)sender {
UIButton *button = (UIButton *)sender;
但是来电为nil
发送sender
。
在UIButton
来电中提供bomb
指针
或者不要使用sender
而是使用UIButton
指针。
UIButton
指针可以来自IBOutlet
。