记录从现在开始到按下按钮的时间?

时间:2011-04-30 21:25:16

标签: iphone objective-c cocoa-touch

我想知道如何记录从运行下面的方法到按下UIButton的时间 - 有人可能会帮忙吗?

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

谢谢,

1 个答案:

答案 0 :(得分: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]);
}

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