2011-04-30 65 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

相关问题