NSURLConnection cancel
是否可以使用回调捕获?
如果我使用此代码
-(void) pleaseStopDownload {
cancelled = YES;
[conn cancel];
conn = nil;
[self myUpdateUImessage];
}
myUpdateUImessage
在此回调之前调用from time to
- (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 比进度 UI 显示。
编辑 问题是关于
NSOperationQueue *tempQueue = [[NSOperationQueue alloc] init];
[conn setDelegateQueue:tempQueue];
正确NSQueue
的是 NSOperationQueue *tempQueue = [NSOperationQueue mainQueue];