Bazı hücrelerde Başlat düğmesine bastığınızda, customCells ile bir TableView var, yükleme başlar. Böyle birçok hücre var, bu yüzden bu indirmeyi paralel olarak (eşzamansız olarak) uygulamam gerekiyor. Ben görüntülerin Paralel indirmeye imkan vermelidir gerekiyordu o zaman uyumsuz kuyruğuna bu yöntemi içermektedirEşzamansız olarak UITableView kullanarak görüntüleri indirmek için NSURLConnection
#define myAsyncQueue dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
: Görüntü indirilmesi ve Tablo görünümünde hücreyi güncellenmesi için sonraki kodu kullanabilirsiniz. - (void) didClickStartAtIndex: (NSInteger) cellIndex withData: Tüm kuyruklar olmadan
(CustomTableViewCell*)data
{
dispatch_async(myAsyncQueue, ^{
self.customCell = data;
self.selectedCell = cellIndex;
ObjectForTableCell* tmp =[self.dataDictionary objectForKey:self.names[cellIndex]];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:tmp.imeageURL]
cachePolicy:NSURLRequestReloadIgnoringLocalCacheData
timeoutInterval:60.0];
self.connectionManager = [[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
});
}
-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
self.urlResponse = response;
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSDictionary *dict = httpResponse.allHeaderFields;
NSString *lengthString = [dict valueForKey:@"Content-Length"];
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
NSNumber *length = [formatter numberFromString:lengthString];
self.totalBytes = length.unsignedIntegerValue;
self.imageData = [[NSMutableData alloc] initWithCapacity:self.totalBytes];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[self.imageData appendData:data];
self.customCell.progressView.progress = ((100.0/self.urlResponse.expectedContentLength)*self.imageData.length)/100;
float per = ((100.0/self.urlResponse.expectedContentLength)*self.imageData.length);
self.customCell.realProgressStatus.text = [NSString stringWithFormat:@"%0.f%%", per];
}
I tried to set this block to queue - main queue - cause its the place where image is already downloaded,
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
dispatch_async(dispatch_get_main_queue(), ^{
self.customCell.realProgressStatus.text = @"Downloaded";
UIImage *img = [UIImage imageWithData:self.imageData];
self.customCell.image.image = img;
self.customCell.tag = self.selectedCell;
});
[self.savedImages setObject:img forKey:self.customCell.nameOfImage.text];
NSNumber *myNum = [NSNumber numberWithInteger:self.selectedCell];
[self.tagsOfCells addObject:myNum];
}
(bunu yorum yaparken) Tüm düzgün çalışır - ama olanlar sadece 1 indirme. Ancak kodları sırayla uygulamaya çalıştığımda, hiçbir şey indirmiyor. Anladığım kadarıyla yanlış anladım ama tanımlayamıyorum.
Şimdiden herhangi bir yardım için çok teşekkürler.
[sadece bu lib deneyin] (https://github.com/rs/SDWebImage) –
@Fahim: AFNetworking
DÜZENLEME kullanarak görüntüsü indirilirken için
, bir tavsiye için teşekkür ederim, ben öğreniyorum ve herhangi bir üçüncü parti kütüphanesi olmadan, kendim tarafından uygulamak istedim, en azından kendim – Melany