0

I followed the code based on here tableview Tutorial and i did successfully show something in my tableview.

I want to change the cell image by using url link from website.

Here is my code:

NSString *str = [NSString stringWithFormat:@"http://piq.codeus.net/static/media/userpics/piq_126382_400x400.png"];
NSString *path = [str stringByReplacingOccurrencesOfString:@"," withString:@"/"];

NSURL *url = [NSURL URLWithString:path];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
cell.imageView.image = [UIImage imageWithData:data];

If I change my str to NSString *str = @"https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSrKOobbDUVMwrrqMkpvfhITeyQewM8Kj0fZg_X_u3TaM-CLi5QfA"; then it will successfully change the image of each cell in table view.

Both urls link to the same image but the first link image size is bigger than second link.

Jonny C
  • 1,943
  • 3
  • 20
  • 36
Ah Hui
  • 41
  • 4

1 Answers1

0

Problem solved. Thanks to @GoodSp33d. For those who are using Xcode 7. Please refer to this solution.

Here is my updated code:

NSString *str = [NSString stringWithFormat:@"your image url"];
NSURL *url = [NSURL URLWithString:str];
NSData *data = [NSData dataWithContentsOfURL : url];
cell.imageView.image = [UIImage imageWithData:data];
Community
  • 1
  • 1
Ah Hui
  • 41
  • 4