timeIntervalSinceReferenceDate

timeIntervalSinceReferenceDate

本文介绍了[NSDate timeIntervalSinceReferenceDate]上的exc_bad_access的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从[NSDate timeIntervalSinceReferenceDate]中发现了奇怪的行为.

I'm getting weird behavior out of [NSDate timeIntervalSinceReferenceDate].

我具有以下功能:

-(void) insertRow{
NSTimeInterval timeNow = [NSDate timeIntervalSinceReferenceDate];
if (timeNow - secondsSinceTableViewScroll <0.5){
    [self insertRow];
    return;
}

NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:[self.itemsToFollow count] - 1];
[self.tableView insertSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
}

这是ASIHTTPRequest requestFinished的回调.如果我在代码中放置一个断点,它可以正常工作.如果我只是尝试运行代码,则在行中会得到exc_bad_access:

which is a callback from an ASIHTTPRequest requestFinished.If I put a breakpoint in the code, it works fine. If I just try to run the code, I get an exc_bad_access on the line:

NSTimeInterval timeNow = [NSDate timeIntervalSinceReferenceDate];

secondsSinceTableViewScroll是在标头中声明的ivar,其设置如下:

secondsSinceTableViewScroll is an ivar declared in the header and set like this:

 secondsSinceTableViewScroll = [NSDate timeIntervalSinceReferenceDate];

有没有主意,为什么在没有断点的情况下为什么要获得exc_bad_access?

Any ideas why I'm getting the exc_bad_access when there is no breakpoint?

谢谢

只有我能找到

我正在检查这样的时间:

I was checking the time like this:

-(void) insertRow{
end = [NSDate timeIntervalSinceReferenceDate];
if(end-start < 0.05){
    [self insertRow];
    return;
}

NSIndexSet *indexSet = [NSIndexSet indexSetWithIndex:[self.itemsToFollow count] - 1];
[self.tableView insertSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
}

我确定某个地方说您无法背对timeIntervalSinceReferenceDate进行调用,这就是它崩溃的原因(无论如何,这种递归循环是一个非常糟糕的主意).

I'm sure somewhere it says you can't have back to back calls of timeIntervalSinceReferenceDate and that's why it was crashing (this kind of recursive loop was a pretty bad idea anyways).

因此,请使用while循环,或者使用更好的NSTimer.

So use a while loop, or better yet an NSTimer.

感谢您的帮助

推荐答案

更改

[self insertRow];

[self performSelector:@selector(insertRow) withObject:nil afterDelay:0];

这篇关于[NSDate timeIntervalSinceReferenceDate]上的exc_bad_access的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-19 00:36