Reputation:
I get images for JSON.like this:-
-(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:-
cell.imageView.image = [imagesarray objectAtIndex:indexPath.row];
But images are not display in UITableViewCell So Please give me any idea about my problem . Thanks in Advanced
Upvotes: 1
Views: 68
Reputation: 49720
The way of loading image in to Table-view from Json is wrong. Better to load array with imageURL and load its Image from URL in to the CellForRowAtIndex
: method
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:
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.
Upvotes: 1
Reputation: 25692
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.
Upvotes: 0