2011-10-21 42 views
3

我收到了来自[NSDate timeIntervalSinceReferenceDate]的奇怪行为。exc_bad_access on [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

NSTimeInterval timeNow = [NSDate timeIntervalSinceReferenceDate]; 

secondsSinceTableViewScroll是在头部声明,并设置这样的伊娃:

secondsSinceTableViewScroll = [NSDate timeIntervalSinceReferenceDate]; 

任何想法,为什么我在没有断点时获得exc_bad_access?

感谢

只有我能找到

我被检查这样的时间件事:

-(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的调用,这就是为什么它崩溃了(这种递归循环反正是一个非常糟糕的主意)。

因此,使用while循环,或更好的NSTimer。

感谢您的帮助,但

+0

我把钱它是一个红色的鲱鱼!上面的代码看起来很好。其他地方的某个地方正在导致访问不良。你运行分析仪吗?僵尸是否启用?如果他们不放弃任何东西,那么现在是时候在乐器中进行一些泄漏分析。 –

+0

+1在StackOverflow上发布实际堆栈溢出问题 –

回答

2

变化

[self insertRow]; 

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

这是干什么的? –

+0

它会阻止你获得堆栈溢出 – logancautrell

+0

即使延迟设置为0? (我想这需要花一些时间来评估方法?) –

2

您的症状表明您实际上正在另一个线程上崩溃。你有其他的线程在运行吗?检查所有线程的回溯。以上是主线,对吗?


编辑:你递归太快,溢出你的堆栈。 “尽可能快地称自己”的半秒钟会很快溢出堆栈。

+0

我不确定如何检查该问题。这行代码正在线程1上执行,exc_bad_access在该行上。线程1是调试器中唯一具有任何内容的线程。有什么你想让我检查的吗? –

+0

发布你的回溯。 –

+0

没有回溯。它说“无法加载最后一帧”。我已经开始使用NSTimer而不是此标志方法。我会发布更新。感谢您的想法,虽然 –

相关问题