2011-09-20 11 views
0

如何將標籤重置爲零,每當用戶點擊圖像時都會計數? 我擁有的當前方法不起作用。IOS - 如何按下按鈕時將數字標籤重置爲零?

這裏是我相信你會需要的代碼:

int number = 0; 

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { 

UITouch *touch = [[event allTouches] anyObject]; 
CGPoint location = [touch locationInView:self.view]; 
if ([self Intersecting:location :Ball]) { 
    number++; 

    [labelCurrentNumber setText:[NSString stringWithFormat:@"%d", number]]; 

    } 
} 

-(IBAction)startMove { 
    buttonStart.hidden = YES; 
    Ball.hidden = NO; 
    labelEasy.hidden = YES; 
    buttonBack.hidden = YES; 

    Destination = CGPointMake(arc4random() % 320, arc4random() % 480); 
    xamt = ((Destination.x - Ball.center.x)/speed); 
    yamt = ((Destination.y - Ball.center.y)/speed); 

    mainTimer = [NSTimer scheduledTimerWithTimeInterval:(0.02) target:self selector:@selector(moveBall) userInfo:nil repeats: YES]; 
    mainInt = 20.00; 
    timer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(countDown) userInfo:nil repeats:YES]; 
} 

請幫我,謝謝你提前。

回答

0

只需爲要更改爲零的數量設置一個整數,並使標籤顯示該整數。然後,所有你需要做的是代碼「當按下按鈕時,在此處設置整數名稱爲0

+0

對不起,我是一個結點。您能否更詳細地向我解釋? –

0

不是聽觸摸事件,並計算交集的,你可能要考慮一個UITapGestureRecognizer。只需添加您的集以零方法作爲目標,並將手勢識別器添加到您的圖像中。