2011-04-30 69 views
0

我想知道如何記錄運行下面的方法所花費的時間,以及何時按下UIButton - 任何人都可以幫忙?從現在開始到按下按鈕的時間?

-(void)informToPress 
{ 
    textLabel.text = @"Test, press the button"; 
    //begin record and end record on button press 
} 

謝謝

回答

3
-(void)informToPress 
{ 
    textLabel.text = @"Test, press the button"; 
    //begin record and end record on button press 

    startDate = [[NSDate alloc]init]; 
} 

-(IBAction)stopTime{ 
    stopDate = [[NSDate alloc]init]; 

    //The actual time in seconds 
    NSLog(@"Time in seconds %f", [stopDate timeIntervalSinceDate:startDate]); 
} 

OR

-(IBAction)calculateTime{ 
     //The actual time in seconds just calculated not stored. 
     NSLog(@"Time in seconds %f", [startDate timeIntervalSinceNow]); 
} 
+0

時間間隔是雙我覺得,這樣你不會想要把一個%F代替%我的? – 2011-04-30 21:57:27

+0

@Zaky THX,我改變了它...... – Cyprian 2011-04-30 22:08:50

+0

此外,試圖打印所花費的時間,到爲textLabel: 「textLabel.text = @」 時間花費%I 「[stopTimer timeIntervalSinceDate:startTimer所]。」但它不起作用,有什麼想法? – buzzkip 2011-04-30 22:16:19

相關問題