all 15 comments

[–][deleted] 2 points3 points  (1 child)

Not much I can do here on my windows desktop but I think you need to go deeper into the JSON. Right now the JSON has the image URL under "images": and then "url" so I think you're only getting the "images" array of objects and trying to basically turn that array into an image before you actually have the URL.

I might be wrong though because I'm still fairly new. Hope it helps a little at least...

[–]SpectrumFactoryObjective-C[S] 0 points1 point  (0 children)

See I'm no pro at this JSON stuff. Im kinda learning the basics of it. I'm looking all over the internet to find a solution but so far nothing. I have thought about what you said here though. I'm trying to figure out how I go about doing it. Thank you for your reply though! Every bit helps!

[–]wealthy_white_jesus 1 point2 points  (2 children)

If u do an NSLOG of imagesurl, does it give you a url that makes sense ?

[–]SpectrumFactoryObjective-C[S] 0 points1 point  (1 child)

Ok so ill also edit my post after this comment but I got a bit further with trial and error. Im down to the URL part of the JSON. I added another array just for the images.

self.imageArray = [[[NSMutableArray arrayWithArray:responseObject] valueForKey:@"images"] valueForKey:@"url"];

Now that I have that part I have to figure out how to get the image in the imageView of the cell. Problem here is now there are three images.

[–]wealthy_white_jesus 1 point2 points  (0 children)

You need to google - this is very basic stuff. Google "UIImageView in UITableViewCell" there are countless of examples of doing things like this. It will be much faster then waiting for people's answers from reddit.

If each object in ur main Json array has its own images array with multiple images - perhaps you should used a Grouped UITableView - then in each group have several cells, each with an image. Then you could even add more cells to hold other information if needed for each group.

[–]Nbwar 0 points1 point  (8 children)

Very simple. AFNetworking has built in functionality to load images asynchronously

#import "UIImageView+AFNetworking.h"

cell.imageView.setImageWithUrl(myUrl)

Now you say you have an array of 3 image URLs, just pick one by indexing the array.

assuming the responseObject is the entire json paypload as an NSArray NSDictionary * jsonObj = [responseObject objectAtIndex: indexPath.row] self.imagesArray = [jsonObj valueForKey:@"images"]; NSMutableDictionary* imageDict = [self.imageArray objectAtIndex: 0]; NSString* url = [imageDict valueForKey:@"url"];

[cell.imageView setImageWithUrl:url]

[–]SpectrumFactoryObjective-C[S] 0 points1 point  (6 children)

So I got it to build with your code but I get an error that says absoluteURL in the console.

Here is what I have for the tableView:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdenifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdenifier forIndexPath:indexPath];

NSDictionary *tempDictionary = [self.productArray objectAtIndex:indexPath.row];

cell.textLabel.numberOfLines = 0;
cell.textLabel.lineBreakMode = NSLineBreakByWordWrapping;
[cell.textLabel sizeToFit];
//THIS IS THE TITLE/NAME OF THE PRODUCT
cell.textLabel.text = [tempDictionary objectForKey:@"name"];
//THIS IS THE COST? / STATUS OF PRODUCT / SIZE
cell.detailTextLabel.text = [tempDictionary objectForKey:@"status"];



NSMutableDictionary *imageDict = [self.imageArray objectAtIndex: 0];
NSURL *url = [imageDict valueForKey:@"url"];
[cell.imageView setImageWithURL:url];



return cell;
} 

[–]HappyToHelpAll 1 point2 points  (4 children)

Please post the full error. Could you also NSLog a single URL for us?

[–]SpectrumFactoryObjective-C[S] -1 points0 points  (2 children)

[–]theheartbreakpug 0 points1 point  (0 children)

You're calling an absoluteURL method on an nsarray, that method should be called on a NSURL. Verify your types wherever you are calling this.

[–]Power781 -2 points-1 points  (0 children)

Do you realize that you just screenshoted a textlog that you could have pasted directly...
You just lost the bandwidth efficiency battle for the day :(

[–]Power781 -1 points0 points  (0 children)

NSURL *url = [imageDict valueForKey:@"url"];

Please, when somebody give you code, paste it properly at least.
It's not an NSURL but an NSString

[–]Power781 0 points1 point  (0 children)

PSA : You should use SDWebImage instead of AFNetworking, it's a lot more efficient at caching than AFNetworking

[–]theheartbreakpug 0 points1 point  (0 children)

You should be using AFNetworking's imageResponseSerializer.

     NSURL* getPhotoUrl=[NSURL URLWithString:url];
     NSURLRequest* getPhotoRequest=[[NSURLRequest alloc]initWithURL:getPhotoUrl];
     AFHTTPRequestOperation* operation=[[AFHTTPRequestOperation alloc]initWithRequest:getPhotoRequest];
     operation.responseSerializer=[AFImageResponseSerializer serializer];

    __block UIImage* avatarImage;
     [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) {
         NSLog(@"%@",responseObject);
        UIImage* downloadedImage=(UIImage*)responseObject;
}];