2014-02-25 123 views
-1

这是我的代码。我想该按钮时,计时器达到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]; 
} 
+1

你应该确定你的陈述的不同之处[self bomb:nil]; 和[自花:寄件人]; 那么你将能够理解,如果可以的话。 –

回答

3

要调用
[self bomb:nil];
nil发件人。

bomb方法使用发送方:

-(IBAction)bomb:(UIButton *)sender { 
    UIButton *button = (UIButton *)sender; 

但呼叫发送nilsender

要么提供的bomb呼叫
UIButton指针或不使用senderUIButton指针。

UIButton指针可以来自IBOutlet

+0

我无法理解它... – fabersky

+0

有人可以帮助我吗? – fabersky