pendant que vous créez l'image cellulaire à ce moment-là, vous devez vérifier l'image est téléchargée ou non si OUI qui peut taper sur l'image autre ActivityIndicator de départ sage et pendant que vous remplissez l'image télécharger vous pouvez arrêter ActivityIndicator pour la meilleure expérience de téléchargement d'image, utilisez la bibliothèque SDWebImage 3rd party et obtenez tous les statuts d'image mentionnés ci-dessous.
Utilisation de l'achèvement Bloc:
// Here we use the new provided sd_setImageWithURL: method to load the web image
[cell.imageView sd_setImageWithURL:[NSURL URLWithString:@"http://www.domain.com/path/to/image.jpg"]
placeholderImage:[UIImage imageNamed:@"placeholder.png"]
completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) {
... completion code here ...
// Add Your Stop Activity Code here.
}];
Une autre façon d'obtenir progrès de l'image utilisation de téléchargement ci-dessous bloc de code:
SDWebImageDownloader *downloader = [SDWebImageDownloader sharedDownloader];
[downloader downloadImageWithURL:imageURL
options:0
progress:^(NSInteger receivedSize, NSInteger expectedSize) {
// progression tracking code
}
completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
if (image && finished) {
// do something with image
// Assign Image to ImageView and stop activity Indicator View
}
}];
SDWebImage Lien: https://github.com/rs/SDWebImage
Ou vous pouvez utiliser votre propre code pour télécharger l'image à l'aide de GCD
dispatch_async
comme mention ci-dessous.
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^(void) {
// You may want to cache this explicitly instead of reloading every time.
NSData *imageData = [NSData dataWithContentsOfURL:[NSURL URLWithString:[self.loader.parsedData[indexPath.row] objectForKey:@"imageLR"]]];
UIImage* image = [[UIImage alloc] initWithData:imageData];
dispatch_async(dispatch_get_main_queue(), ^{
// Capture the indexPath variable, not the cell variable, and use that
UITableViewCell *blockCell = [tableView cellForRowAtIndexPath:indexPath];
blockCell.imageView.image = image;
[blockCell setNeedsLayout];
//Stop Your ActivityIndicator View hare
});
});
J'espère que cela vous aidera.
Utilisez MBProgressHud https://github.com/jdg/MBProgressHUD –
votre code postal de 'TableView' et où vous téléchargez l'image. – Dravidian
S'il vous plaît poster le code dans la méthode 'PicturePerformGesture' –