Iphone 如何从数组中获取url并在表视图中显示图像

Iphone 如何从数组中获取url并在表视图中显示图像,iphone,objective-c,ios,Iphone,Objective C,Ios,提前谢谢。我获取数组中的图像url myarray = { "http://www.abc.com/uploads/sarab.jpg", .... }; 现在我不知道如何访问表视图中的图像?是否有帮助的示例代码?您应该这样做 要从数组中获取URL,请将此代码放入CellForRowatineXpath中,这将帮助您 NSString *str = [YOUR_ARR objectAtIndex:indexPath.row]; NSURL *url = [NSURL URLWithString

提前谢谢。我获取数组中的图像url

myarray = { "http://www.abc.com/uploads/sarab.jpg", .... };

现在我不知道如何访问表视图中的图像?是否有帮助的示例代码?

您应该这样做

要从数组中获取URL,请将此代码放入CellForRowatineXpath中,这将帮助您

NSString *str = [YOUR_ARR objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:str];
首先,将URL转换为NSData,然后将数据分配给图像

NSData *imgData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imgData];
然后呢

cell.imageView.image = image;

快乐编码..

你应该这样做

要从数组中获取URL,请将此代码放入CellForRowatineXpath中,这将帮助您

NSString *str = [YOUR_ARR objectAtIndex:indexPath.row];
NSURL *url = [NSURL URLWithString:str];
首先,将URL转换为NSData,然后将数据分配给图像

NSData *imgData = [NSData dataWithContentsOfURL:url];
UIImage *image = [UIImage imageWithData:imgData];
然后呢

cell.imageView.image = image;

快乐编码..

将此代码放入cellForRowAtindexPath中,它将正常工作:

NSData *imageData= [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[myarray objectAtIndex:indexPath.row]]];
cell.imageView.image=[UIImage imageWithData:imageData];

将此代码放入cellForRowAtindexPath,它将正常工作:

NSData *imageData= [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:[myarray objectAtIndex:indexPath.row]]];
cell.imageView.image=[UIImage imageWithData:imageData];

通过以下方法,您可以实现以下目标:

NSString *strImageUrl = [myarray objectAtIndex:indexpath.row];
NSURL *url = [NSURL URLWithString: strImageUrl];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]]; 
UIImageView *displayimage = [[UIImageView alloc] init];
[displayimage setImage:image];
如果有任何困难,请告诉我


干杯

通过以下方式,您可以实现以下目标:

NSString *strImageUrl = [myarray objectAtIndex:indexpath.row];
NSURL *url = [NSURL URLWithString: strImageUrl];
UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]]; 
UIImageView *displayimage = [[UIImageView alloc] init];
[displayimage setImage:image];
如果有任何困难,请告诉我


干杯

如果我有一个带有字符串和图像url的数组,那么我如何在不使用数组索引号的情况下获取图像url。像myarray={“india”,123654,“,…}我认为您管理阵列的方式非常奇怪。您可以从数组中获取对象,然后从字符串中检查字符串中是否存在“www”或“.jpg、.png”。我的建议是在NSObject类上创建,它的属性有Title、Number、ImageUrl(India,123456,abc.com/uploads.srarb.jpg)。并将该类的对象添加到数组中。所以,您将通过使用“Index.Row”获取对象。然后可以使用像classObject.imageUrl这样的imageUrl。然后做这个过程。希望你得到答案。如果我有一些字符串和图像url的数组,那么我如何可以获取图像url而不使用数组的索引号。像myarray={“india”,123654,“,…}我认为您管理阵列的方式非常奇怪。您可以从数组中获取对象,然后从字符串中检查字符串中是否存在“www”或“.jpg、.png”。我的建议是在NSObject类上创建,它的属性有Title、Number、ImageUrl(India,123456,abc.com/uploads.srarb.jpg)。并将该类的对象添加到数组中。所以,您将通过使用“Index.Row”获取对象。然后可以使用像classObject.imageUrl这样的imageUrl。然后做这个过程。希望你得到答案。