0

I tried this link, but I didn't get my solution.

I want to display and load images from URL that are visible in UITableViewCell and other cell images have to load when we scroll table view in Objective-C.

  • Have you used any library, show what you tried so far? – Imad Ali Jun 05 '17 at 07:53
  • 4
    Possible duplicate of [Async image loading from url inside a UITableView cell - image changes to wrong image while scrolling](https://stackoverflow.com/questions/16663618/async-image-loading-from-url-inside-a-uitableview-cell-image-changes-to-wrong) – Harshal Valanda Jun 05 '17 at 07:54

2 Answers2

0

use SDWebImage for this. it has almost all features what you need. It's also easy to coding like this.

Objective C

[imageView sd_setImageWithURL:[NSURL URLWithString:@"your domain"]
             placeholderImage:[UIImage imageNamed:@"placeholder.png"]];

Additional:

swift 3:

imageView.sd_setImage(with: URL(string: "your domain"), placeholderImage: UIImage(named: "placeholder.png"))
elk_cloner
  • 2,049
  • 1
  • 12
  • 13
  • Thanks for your answer. I was implementing it but i want to modify it to display/download only visible cells image ..But using this it can download all the cells continuosly ..Can u guide me how to do it – Rajashekar Korlagunta Jun 06 '17 at 04:06
  • Welcome.If this answer is helpful i hope you will accept it.:) We are here to help you.:) – elk_cloner Jun 06 '17 at 04:14
0

Rajashekar simply you can do this

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *strCell=@"cell";
    UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:strCell];
    if (cell==nil) {
        cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:strCell];
    }
    NSString *strImgURL = @"YourImageURL";
    NSError* error = nil;
    NSURL *fileURL = [NSURL fileURLWithPath:strImgURL];
    NSData* data = [NSData dataWithContentsOfURL:fileURL options:NSDataReadingUncached error:&error];
    if (error) {
        NSLog(@"%@", [error localizedDescription]);
    } else {
        NSLog(@"Data has loaded successfully.");
    }
    UIImage *img = [[UIImage alloc] initWithData:data];
    cell.imageView.image = img;

    return cell;
}
user3182143
  • 9,459
  • 3
  • 32
  • 39