MissCoder87
MissCoder87

Reputation: 2669

Loading an image from multidimensional array in to UIImageView

I'm loading an image to a custom cell and I build up an array throughout my code from XML which I want to set to my UIImageView on my nib file.

My array gets built up to totalArray and then I do the following in my cellForRowAtIndexPathT:

newObj1=[totalArray objectAtIndex:indexPath.row];
aCell.lblRouteText.text = newObj1.routeText;

And the following to load my image works (static):

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://imageurl.jpg"]]];
aCell.imgRoute.image = image;

However, when I try to put my array in using the following:

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[newObj1.routeImage]]];

I get an error of identifier expected

Any tips?

Tom

Upvotes: 0

Views: 350

Answers (1)

occulus
occulus

Reputation: 17014

You're writing [newObj1.routeImage] where you just need newObj1.routeImage, i.e. your final line should probably read:

UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:newObj1.routeImage]];

When you use square brackets (and not in the context of a C array), you should always have something of the form [x y], which means 'send the message y to the receiver x'.

Note on threading: be careful about using [NSData dataWithContentsOfURL:], because it blocks while the URL contents are fetched. If you call this on the main thread, you will block your UI and the app will be unresponsive.

(Btw, if you're posting error messages, it's best to copy and paste the full actual error line(s) from the console if possible -- it maximises our chance of understanding the problem.)

Upvotes: 1

Related Questions