0
是否有可能使用回调赶上NSURLConnection cancel
?NSURLConnection取消回调
如果我使用此代码
-(void) pleaseStopDownload {
cancelled = YES;
[conn cancel];
conn = nil;
[self myUpdateUImessage];
}
不时myUpdateUImessage
这个回调
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(@"didReceiveData");
if (!cancelled) {
//this code inside brackets suddenly is calling:(
//not always but from time to time
summ += data.length;
if (_progressHandler != nil)
_progressHandler(data, summ, max);
} else {
return;
}
}
,所以用户界面不能正确更新之前调用!也就是说,最终用户界面显示的是进度UI。
编辑 的问题是关于
NSOperationQueue *tempQueue = [[NSOperationQueue alloc] init];
[conn setDelegateQueue:tempQueue];
正确NSQueue
是NSOperationQueue *tempQueue = [NSOperationQueue mainQueue];