Xcode tableview cell无法通过url显示图像

问题描述:

我跟着代码基于这里tableview Tutorial,我成功地显示了我的tableview中的东西。Xcode tableview cell无法通过url显示图像

我想通过使用网站的链接来更改单元格图像。

这里是我的代码:

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]; 

如果我改变我的海峡到 NSString *str = @"https://encrypted-tbn2.gstatic.com/images?q=tbn:ANd9GcSrKOobbDUVMwrrqMkpvfhITeyQewM8Kj0fZg_X_u3TaM-CLi5QfA"; 那么它会成功改变表视图​​每个细胞的图像。

两个网址链接到相同的图像,但第一个链接图像大小比第二个链接大。

+0

是否使用Xcode的7?也许'HTTP' URL默认被阻止。 http://*.com/questions/30731785/how-do-i-load-an-http-url-with-app-transport-security-enabled-in-ios-9 – GoodSp33d

+0

其实你称之为同步它需要一些延迟 –

+0

@ GoodSp33d,是的,即时通讯使用Xcode 7.我能做些什么来解锁它? –

问题已解决。感谢@ GoodSp33d。 适用于使用Xcode 7的用户。请参考this solution

这里是我更新的代码:

NSString *str = [NSString stringWithFormat:@"your image url"]; 
NSURL *url = [NSURL URLWithString:str]; 
NSData *data = [NSData dataWithContentsOfURL : url]; 
cell.imageView.image = [UIImage imageWithData:data];