iOS 5核心数据冻结 [英] iOS 5 Core Data freeze

查看:117
本文介绍了iOS 5核心数据冻结的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试做以下简单的事情:

  NSArray * entities = [context executeFetchRequest:inFetchRequest error:& fetchError ]; 

没什么好奇的。但是这在iOS 5中冻结,它在iOS 4正常工作。我不会得到异常,警告或错误;我的应用程序只是冻结。



请帮助我!我在这里死了! ;)

解决方案

感谢此页面提供的有关如何解决从iOS4升级时出现的冻结问题的提示。这是我从iOS开始编程以来发现的最恼人的问题。



我发现了一个快速的解决方案,其中只有几个调用上下文

 

code> [self performSelectorOnMainThread:@selector(stateChangeOnMainThread :) withObject:[NSDictionary dictionaryWithObjectsAndKeys:state,@state,nil] waitUntilDone:YES];

要检测从另一个线程调用上下文的地方,可以在NSLog上放置一个断点

 <$ c $ 

c> if(![NSThread isMainThread]){
NSLog(@不是主线程...);
}

我希望这可能会有所帮助...


I try to do the following simple thing:

NSArray * entities = [context executeFetchRequest:inFetchRequest error:&fetchError];

Nothing fancy. But this freezes in iOS 5, it works fine in iOS 4. I don't get exceptions, warnings or errors; my app just simply freezes.

Please help me out! I'm dying here! ;)

解决方案

Thanks for the hints given in this page on how to solve this freezing issue which appeared on upgrading from iOS4. It has been the most annoying problem I have found since I started programming on iOS.

I have found a quick solution for cases where there are just a few calls to the context from other threads.

I just use performSelectorOnMainThread:

    [self performSelectorOnMainThread:@selector(stateChangeOnMainThread:) withObject: [NSDictionary dictionaryWithObjectsAndKeys:state, @"state", nil] waitUntilDone:YES];

To detect the places where the context is called from another thread you can put a breakpoint on the NSLog on the functions where you call the context as in the following piece of code and just use performSelectorOnMainThread on them.

if(![NSThread isMainThread]){
     NSLog(@"Not the main thread...");
}

I hope that this may be helpful...

这篇关于iOS 5核心数据冻结的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆