[英]UIImageView to UITableViewCell
I get images for JSON.like this:- 我得到JSON的图像,像这样:-
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSMutableArray *al=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
for (NSDictionary *diction in al)
{
NSString *geting =[diction valueForKey:@"dealimage"];
NSLog(@"dealimage is %@",geting);
NSData *getdata=[[NSData alloc]initWithData:[NSData dataFromBase64String:geting]];
NSLog(@"good day %@",getdata);
dataimages=[UIImage imageWithData:getdata];
NSLog(@"dataimages %@",dataimages);
[imagesarray addObject:dataimages];
}
NSLog(@"images array is array%@",imagesarray);
NSLog(@"dataimages 8images %@",dataimages);
}
When i print images array it show like this:- 当我打印图像数组时,它显示如下:-
images array is array(
"<UIImage: 0x7539b70>",
"<UIImage: 0x7176e00>",
"<UIImage: 0x7182960>",
"<UIImage: 0x7185d40>",
"<UIImage: 0x7541d00>",
"<UIImage: 0x7186e30>",
"<UIImage: 0x7186ff0>",
"<UIImage: 0x7187410>"
)
What I tried is NSString to pass to NSData via Base64String and then NSData pass to UIImage and then UIImage pass to the NSMutablearray(imagearray).Now i pass the this array to UITableViewCell like is:- 我尝试过的是将NSString通过Base64String传递给NSData,然后将NSData传递给UIImage,然后将UIImage传递给NSMutablearray(imagearray)。现在,我将该数组传递给UITableViewCell如下:
cell.imageView.image = [imagesarray objectAtIndex:indexPath.row];
But images are not display in UITableViewCell So Please give me any idea about my problem . 但是图像没有显示在UITableViewCell中,所以请给我有关我的问题的任何想法。 Thanks in Advanced
提前致谢
The way of loading image in to Table-view from Json is wrong. 从Json将图像加载到Table-view的方法是错误的。 Better to load array with imageURL and load its Image from URL in to the
CellForRowAtIndex
: method 最好使用imageURL加载数组并将其Image从URL加载到
CellForRowAtIndex
:方法中
For example: 例如:
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSMutableArray *al=[NSJSONSerialization JSONObjectWithData:webData options:0 error:nil];
for (NSDictionary *diction in al)
{
NSString *geting =[diction valueForKey:@"dealimage"];
NSLog(@"dealimage is %@",geting);
[imagesarray addObject:geting]; // here adding image URL in side the Array
}
[self.tableview reloadData];
}
and CellForAtIndex: 和CellForAtIndex:
cell.imageView.image=[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[imagesarray objectAtIndex:indexPath.row]]]];
And for better smooth parformance use asynchronous image loading with help of SDWebImage or many other library that load you image from url with catch and performance faster. 为了获得更好的平滑性能,请在SDWebImage或许多其他库的帮助下使用异步图像加载,以更快的速度从URL加载图像。
NSLog(@"images array is array%@",imagesarray);
yourTableView.dataSource = self;//or your object
[yourTableView reloadData];
will make table view to refresh the data. 将使表视图刷新数据。
if you didn't set the dataSource then table view will not look for table data to show. 如果您未设置dataSource,那么表视图将不会查找要显示的表数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.