Reputation: 21808
I'm using NSRunLoop in my application. Just one statement
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
performed in for loop. It is needed to update certain text each two seconds for three times. Everything works fine but when i quit the screen where it runs (and while it is running which is most important ting) and then enter the screen again and then quit it again my app crashes. I presume i have to stop running NSRunLoop if i quit when it's running but i have no idea how to do that. Would you please advice me something?
This is my loop:
for (int i = 1;i <= 3;i++)
{
int result = [self analyzeCards];
((UILabel *)[bidLabels objectAtIndex:i]).text = [bidResults objectAtIndex:result];
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]];
bidIndexes [i - 1] = result;
}
Upvotes: 0
Views: 1353
Reputation: 89509
Thanks for modifying your question to include a bit of source code.
I'd recommend against doing the runUntilDate
thing you have been doing and do this as a detached thread instead (making sure to actually do the updating the labels -- the user interface -- on the main thread).
The crash itself is most likely happening because the objects in your bidLabels
array are stale or released or just simply garbage. Reset that array each time you re-open the window.
Upvotes: 1