這是我的代碼。我想該按鈕時,計時器達到0變化,但它不工作:從void調用IBAction
-(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];
}
你應該確定你的陳述的不同之處[self bomb:nil]; 和[自花:寄件人]; 那麼你將能夠理解,如果可以的話。 –