0

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

1 Answer 1

1

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.)

Sign up to request clarification or add additional context in comments.

1 Comment

D'oh, so easy. Thanks for that

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.