要判断一个动作结束后的时间到现在是否大于某特定的时间,怎么做- -!

解决方案 »

  1.   

    如果是2s后执行一个方法
    [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(你的方法名) userInfo:nil repeats:NO];
    如果是监听动作发生后的时间就需要新建一个线程了
      

  2.   

    那你可以这样,首先加入[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(onTime) userInfo:nil repeats:NO];
    在每个动作(我觉得你的意思应该是每个动作绑定在一个方法里)里都做一个flag标记,标记默认为NO,如果其他动作执行,就将flag置为YES,
    应该类似
    - (void)其他任何动作的方法 {
        flag = YES;
        //其他方法
    }
    然后在onTime这么写
    - (void)onTime 
    {
        if(!flag) {
            另外一个动作
        }
    }
      

  3.   

    // REF:http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html
    NSTimeInterval time = [[NSDate date] timeIntervalSince1970];// REF:http://developer.apple.com/library/mac/#documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_DataTypes/Reference/reference.html
    NSTimeIntervalUsed to specify a time interval, in seconds.
    typedef double NSTimeInterval;
    DiscussionNSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.得到两个NSTimeInterval的秒数后减一下就知道了。
      

  4.   

    NSDate 有个compare:方法,可以用这个方法来比较判断