Sitaram Naidu Sitaram Naidu - 5 months ago 17
Objective-C Question

how to insert json image data in to uitableview ios(obj -C)

hear is the response and please do explain in detail
Thanks in advance

{
"success": "true",
"data": {
"per_page": 25,
"total_records": "12",
"products": [
{
"product_id": "48",
"price": "1699.0000",
"image": "data/newimages/1.jpg",
"status": "1",
"description": "nill",
"name": "Buy 2 Denim Jeans & 1 Round Tee & 1 Casual Shirt get one Casual Watch free"
},
{
"product_id": "47",
"price": "2500.0000",
"image": "data/newimages/2.jpg",
"status": "1",
"description": "nill",
"name": "2 Branded denim Jeans & 2 Casual Shirt + 1 round neck tee and get a Watch , Card Holder free"
},
{
"product_id": "43",
"price": "1999.0000",
"image": "data/newimages/12.jpg",
"status": "1",
"description": "nill",
"name": "Complete Formal Combo By 2 cotton formal trousers & 2 Formal Shirts + 1 formal shoe & 2 formal Belts"
},
{
"product_id": "40",
"price": "1599.0000",
"image": "data/newimages/8.jpg",
"status": "1",
"description": "nill",
"name": "7 printed super hero & disney Round Neck Tees get 1 Sneaker Shoes free"
},
{
"product_id": "39",
"price": "2000.0000",
"image": "data/newimages/18.jpg",
"status": "1",
"description": "nill"
"name": "Its time to steel the looks with these 5 100% cotton formal Shirts"
}
]
}

Answer

You can easily do this by downloading SDWebImage library, after downloading sdwebimage you need to first import it

#import "UIImageView+WebCache.h"

After import check my "cellForRowAtIndexPath" method of UITableView

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

static NSString *CellIdentifier = @"cell";
UITableViewCell *cell;
cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
[cell.ImageView sd_setImageWithURL:[NSURL URLWithString:@“URL String”] placeholderImage:[UIImage imageNamed:@“Place holder image name“]];
return cell;}

You can get the array using the below code

NSDictionary *dictionaryYouAlreadyHave;
NSArray *productArray = [[[dictionaryYouAlreadyHave objectForKey:@"data"] objectForKey:@"products"]];

And you can get image name using below code

NSDictionary *dict = [productArray objectAtIndex:0];
NSString *imgName = [dict objectForKey:@"image"];
Comments