iPhone timeIntervalSinceDate 不抛出错误,或者工作
我试图找出两个 NSDate 之间的区别。这曾经起作用并打印出差异,但再也没有起作用。我不记得在一次工作后改变过任何事情。有什么想法吗?哦,它不会抛出错误,如果我注释掉这个片段,一切都会正常。
//----------- Touches Begin
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
touchBegins = [NSDate date];
NSLog (@" Tap: %d ", tapTotal);
NSLog (@"<=========================>");
NSLog (@"Method: touchesBegines & Ends");
NSLog (@" Touch Begin: %@", touchBegins);
// [self updateLabelsFromTouches:touches];
}
//----------- Touches End
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
touchEnds = [NSDate date];
NSLog (@" Touch Ends : %@", touchEnds );
@try {
NSLog(@"%@", touchEnds);
NSTimeInterval elapsed = [touchEnds timeIntervalSinceDate:touchBegins];
NSLog (@" Finger Down: %f", elapsed);
} @catch (NSException *ex) {}
NSLog (@" ");
[self updateLabelsFromTouches:touches];
}
安慰:
[Session started at 2010-10-27 10:27:18 -0400.]
Tap: 0
<=========================>
Method: touchesBegines & Ends
Touch Begin: 2010-10-27 14:27:22 GMT
Touch Ends : 2010-10-27 14:27:22 GMT
I'm trying to find the difference between two NSDates. This worked once and printed the difference, but has never worked again. I don't remember changing any thing after the one time it worked. Any ideas? Oh, and it doesn't throw an error, and if I comment out this snippet everything works.
//----------- Touches Begin
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
touchBegins = [NSDate date];
NSLog (@" Tap: %d ", tapTotal);
NSLog (@"<=========================>");
NSLog (@"Method: touchesBegines & Ends");
NSLog (@" Touch Begin: %@", touchBegins);
// [self updateLabelsFromTouches:touches];
}
//----------- Touches End
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
touchEnds = [NSDate date];
NSLog (@" Touch Ends : %@", touchEnds );
@try {
NSLog(@"%@", touchEnds);
NSTimeInterval elapsed = [touchEnds timeIntervalSinceDate:touchBegins];
NSLog (@" Finger Down: %f", elapsed);
} @catch (NSException *ex) {}
NSLog (@" ");
[self updateLabelsFromTouches:touches];
}
Console:
[Session started at 2010-10-27 10:27:18 -0400.]
Tap: 0
<=========================>
Method: touchesBegines & Ends
Touch Begin: 2010-10-27 14:27:22 GMT
Touch Ends : 2010-10-27 14:27:22 GMT
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:查看您添加的额外代码,您没有保留 touchBegins。试试这个:
我很惊讶它不只是当你调用 timeIntervalSinceDate 时崩溃:) - 事实上,它是,但你捕获了异常然后忽略它!
您应该在 @catch 中添加一些异常日志记录;只需这样做就可以了:
您可能会看到一条日志消息,上面写着“无法识别的选择器”之类的内容 - 我敢打赌,您肯定会看到一些有趣的东西!
看看这个: http://www.cplusplus.com/reference/clibrary/ cstdio/printf/
%d 是一个整数 - 尝试 %f :)
EDIT: Looking at the extra code you have added, you're not retaining touchBegins. Try this :
I'm surprised it's not just crashing when you call timeIntervalSinceDate :) - in fact, it is but you're catching the exception and then ignoring it!
You should add some exception logging in your @catch; just this should do it :
You might see a log message that says something like 'unrecognized selector' - you'll certainly see something interesting I'll bet!
Have a look at this : http://www.cplusplus.com/reference/clibrary/cstdio/printf/
%d is an integer - try %f :)