求教, iphone开发中时间判断
要判断一个动作结束后的时间到现在是否大于某特定的时间,怎么做。。。- -!
[解决办法]
那你可以这样,首先加入[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) {
另外一个动作
}
}
[解决办法]
// 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
NSTimeInterval
Used to specify a time interval, in seconds.
typedef double NSTimeInterval;
Discussion
NSTimeInterval is always specified in seconds; it yields sub-millisecond precision over a range of 10,000 years.
得到两个NSTimeInterval的秒数后减一下就知道了。
[解决办法]
NSDate 有个compare:方法,可以用这个方法来比较判断