用ASIHttpRequest进行异步加载数据时,加载成功后会调用代理函数
1
|
- (
void
)requestFinished:(ASIHTTPRequest *)request
|
开始我以为会在当前线程中执行,后来发现有时是,有时会跑到主线程中执行,这问题一直纠结至今。
今天使劲google一番,终于得到结果,在ASIHTTPRequest.m文件中有这么一段
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
- (
void
)requestFinished
{
#if DEBUG_REQUEST_STATUS || DEBUG_THROTTLING
NSLog
(
@
"[STATUS] Request finished: %@"
,
self
);
#endif
if
([
self
error
] || [
self
mainRequest
]) {
return
;
}
if
([
self
isPACFileRequest
]) {
[
self
reportFinished
];
}
else
{
[
self
performSelectorOnMainThread
:
@selector
(reportFinished)
withObject
:
nil
waitUntilDone
:[
NSThread
isMainThread
]];
}
}
|
不使用PACFileRequest即自动化脚本(PAC是个啥东西?自己google去吧 – -)时,会到主线程中去执行函数reportFinished,这个函数会进而调用代理函数:
1
|
- (
void
)requestFinished:(ASIHTTPRequest *)request
|
还是不要刻意到主线程中去调用的好,所以直接把自动脚本判断语句删掉,只需要[self reportFinished]就行了。