我有我使用在委託協議使用NSURLConnection的在NSURLConnection中控制接收數據的順序?
NSURL *url = [NSURL URLWithString:URLString];
NSMutableURLRequest *urlRequest = [NSMutableURLRequest
requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:2.0f];
// Run network request asynchronously
NSURLConnection *urlConnection = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
接收來自遠程服務器相關聯的圖像的URL的陣列
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// As chuncks of the image are received, we build our data file
[self.imageData appendData:data];
}
最後
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// All data has been downloaded, now we can set the image in the images array
_img = [UIImage imageWithData:self.imageData];
[self.imagesArray insertObject:_img atIndex:_index];
[self.imageData setLength:0];
_index = _index+ 1;
}
,但該命令的收到並不總是相同的發送URL請求的順序我嘗試使用實例變量索引將這些圖像插入薩姆在圖像數組中的順序,但這並不總是工作,我仍然得到無序列表,任何人都可以指出我在如何實現這一目標的正確方向。
感謝人... setImageWithURLRequest做得很漂亮 – carelesslyChoosy