Multiple async requests at once in objective c

后端 未结 1 1935
渐次进展
渐次进展 2020-12-11 10:46

I have am downloading multiple images from a web server at the same time, and I the problem is they are getting mixed up with each other.

dispatch_async(disp         


        
相关标签:
1条回答
  • 2020-12-11 11:14

    You can use "AsyncImageView" class files it will load image synchronously and it shows the activity indicator while image loading

    AsyncImageView is the class file in which it will create connection for each call and when image data downloading completed it will return image for imageview. and if image is already in cache then just return image without creating connection.

    You can download "AsyncImageView" class files from following link:- https://www.dropbox.com/s/peazwjvky9fsjd7/Archive.zip

    in .m file import AsyncImageView Class

      #import "AsyncImageView.h" 
    

    in your tableview cell at indexpath method

    -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
    {
         static NSString *CellIdentifier = @"SimpleTableCell";
         UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    
         UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(X, y, width, height)];
    
         NSString *imageURL = [NSString stringWithFormat: @"www.xyz.image.png"];
         AsyncImageView *async = [[AsyncImageView alloc]initWithFrame:CGRectMake(0, 0, width, height)];
        [async loadImageFromURL:[NSURL URLWithString:imageURL]];
        [imageView addSubview:async];
        [cell addSubview:imageView];
        return cell;
    }
    

    try this your problem will solve.

    0 讨论(0)
提交回复
热议问题