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];