2014-02-25 84 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