我遇到了线程问题。 当我在线程繁忙时在2个屏幕之间漫游几次之后。线程不会执行每一行..,当它必须返回到主线程时,断点才会消失。 有人可以帮我吗?iOS - 线程不会回到主线程
我在释放视图时释放线程。
感谢,
- (void)fetchFeedDataIntoDocument
{
NSString * labelString = [NSString stringWithFormat:@"Feed Fetcher %@", self.pageTitle];
const char *label = [labelString UTF8String];
self.fetchF = dispatch_queue_create(label, NULL);
dispatch_async(self.fetchF, ^{
NSArray *feeds = [FeedFetcher getDataForJson:self.pageTitle downloadBy:@"up"];
NSDictionary *lastfeed;
AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate];
NSManagedObjectContext *context = [appDelegate getManagedObjectContext];
if ([feeds count] > 0)
{
lastfeed = [feeds objectAtIndex:0];
[FeedFetcher setLastUpdateIdToCatgorie:self.pageTitle WithId:[lastfeed objectForKey:@"id"] AndPulishDate:[lastfeed objectForKey:@"publish_up"]];
}
for (NSDictionary *feedInfo in feeds) {
[Feed FeedWithInfo:feedInfo InManageObject:context];
}
NSError *error = nil;
[context save:&error];
if (error){
NSLog(@"Error save : %@", error);}
dispatch_async(dispatch_get_main_queue(), ^{
[self setupFetchedResultsController];
[self.tableView reloadData];
[self downloadImagesForFeeds:feeds];
});
});
现在,我得到这个错误:),终止应用程序由于未捕获的异常‘NSInvalidArgumentException’,原因:‘父的NSManagedObjectContext必须使用NSPrivateQueueConcurrencyType或NSMainQueueConcurrencyType’ –
OK,这意味着你使用的是“默认“通过Xcode的模板创建MOC我会在一分钟内添加一段代码,上面的回答 –
非常感谢你一定要,我认为这是解决:d,它的工作现在罚款 –