嗨我有一个从网址获取图像的问题。即时通讯从一个网络服务获取这些网址,然后加载图像1和1附加在每个网址。从url中获取图像为空值
-(void)downloadMyfriendReqImage:(NSIndexPath *)path
{
if (path.row<[arrayPendingRequests count]) {
NSString *str=[[arrayPendingRequests objectAtIndex:path.row]valueForKey:@"USERIMAGE"];
UIImage *img = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:str]]];
if (img==nil) {
img=[UIImage imageNamed:@"placeholder.png"];
}
[dicPendingReqImages setObject:img forKey:str];
[tblFriendRequests performSelectorOnMainThread:@selector(reloadData) withObject:@"TAG_29" waitUntilDone:NO];
}
}
这是我用来加载图像的方式。但问题是一些图像没有得到。 img
成为空值。但我在android中有相同的应用程序。它完美地加载所有这些图像。这有什么问题..任何人都可以帮助我。
感谢rply。如果它采取超时req为什么它不影响到Android的? – iDia
它可能是android使用代理,反应更快?你有没有看过NSData的内容? –
@iDia使用['dataWithContentsOfURL:options:error:'],而不是'dataWithContentsOfURL'(https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Classes/NSData_Class/Reference/Reference .html#// apple_ref/occ/clm/NSData/dataWithContentsOfURL:options:error :)然后你可以看一下'NSError'来发现是否出了问题,如果是的话,是什么。 – Rob