从方法中调用的方法呼叫主线程
-
11-12-2019 - |
题
我已经从appdelegate拨打了类方法,如下所示:
RankingAndSMProcess *process = [RankingAndSMProcess alloc];
[process performSelectorInBackground:@selector(DoRankingAndSocialMediaProcessing) withObject:nil];
[process release];
.
此方法调用其他方法:
@try {
[self GoForRankingProcess];
[self updateItemsForPeerindex];
[self updateItemsForKloat];
[self updateItemsForKred];
}
@catch (NSException *exception) {
NSLog(@"An Error has been occured:%@", exception);
}
@finally {
[items release];
[profile release];
}
.
是否在RankingAndSmprocess中执行从DorankingAndsocialMediaProcessing方法中调用的所有方法都必须以与DorankingAndsocialMediaProcessing在后台线程相同的方式调用?或者这里有另一个潜在问题吗?
目前,我不认为在没有收集新数据的情况下被解雇任何处理方法。
在添加更改呼叫之前,在后台执行在后台中的所有方法和整个过程都按预期工作。
解决方案
创建一个nsoperation并将此操作添加到nsoperationqueue。 这将创建一个平行于主线程的新线程,它也将执行您的方法。
以下是一些有用的链接:
http://www.icodeblog.com/tag/nsoperation/
http://www.cimgf。COM / 2008/02 / 16 / Cocoa-Tutorial-nsoperation-and-nsoperationQueue /
希望这将为您提供帮助。
享受编码:)
其他提示
所有其他方法都在做什么?如果它是一种网络请求,例如可能需要运行循环,以便背景线程实际上能够执行任务。
不隶属于 StackOverflow