我在我的应用程序中使用NSRunLoop。只有一句话
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:2]]; 在for循环中执行。需要每两秒更新一次特定文本三次。一切都很好,但当我退出它运行的屏幕(当它运行时,这是最重要的),然后再次进入屏幕,然后再次退出,我的应用程序就崩溃了。我假设如果我在NSRunLoop运行时退出,我将不得不停止运行它,但我不知道如何做到这一点。你能给我一些建议吗?
这是我的循环:
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;
}发布于 2011-11-26 20:18:35
感谢您将您的问题修改为包含一些源代码。
我建议不要做你一直在做的runUntilDate的事情,而是作为一个分离的线程(making sure to actually do the updating the labels -- the user interface -- on the main thread)来做。
崩溃本身很可能是因为您的bidLabels数组中的对象已过时或已释放,或者只是垃圾。每次重新打开窗口时重置该数组。
https://stackoverflow.com/questions/8278190
复制相似问题