I’m getting weird behavior out of [NSDate timeIntervalSinceReferenceDate].
I have the following function:
-(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];
}
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 is an ivar declared in the header and set like this:
secondsSinceTableViewScroll = [NSDate timeIntervalSinceReferenceDate];
Any ideas why I’m getting the exc_bad_access when there is no breakpoint?
Thanks
Only thing I could find
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];
}
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).
So use a while loop, or better yet an NSTimer.
Thanks for the help though
Change
to