views:

49

answers:

3

Hello people that are way smarter than me,

I got two xml elements, one is title and the other URL of image. I am trying to show both the UILabel and UIImageView. My problem is the image not showing up.

Here is what I have done so far... If I pass _track.consultant_pic into an UILabel I can see the string (http://mysite.com/ted.jpg) inside my label. So I know the data is being passed from the XML.

If I write the actual path of the url into NSURL *url it works. So I know my set image code from UIImage to UIImageView is correct.

A: 

There might be some encoded characters in your URL which prevent the image form being loaded. See this page for further information. What does NSLog(_track.consultant_pic); say? Do you spot any encoded chars there?

Phlibbo
I have tried changing me XML to: <consultant_pic>@"http://localhost:8888/IMAGES/ted.jpg"</consultant_pic> So I don't think its an encoded character?
slowman21
A: 

I think your best bet would be to use dataWithContentsOfURL:options:error:, and inspect the NSError object for any useful information about what went wrong, like so:

NSError *error = nil;
NSData *data = [NSData dataWithContentsOfURL:url options:0 error:&error];
if (error) {
    NSLog(@"%@: %@", [error localizedDescription], [error localizedFailureReason]);
}

On an unrelated note, your method has a memory leak: an UIImageView retains its image, so you need to add [currentImage release]; at the end of your method.

EDIT: Looking at the code you just pasted, it could just be that you've simply forgotten to connect the view_consultant_pic outlet to your TracksDetailViewController in Interface Builder. Double check that before you do anything else, it's such a common oversight.

L Cassarani
Thanks for looking out Cassarani. I have added the release. Please let me know if I have that on the right spot. Still a noob at this. Also can you help me out with a little more code? How do I write in option:error?
slowman21
I've edited my answer to include an example of `dataWithContentsOfURL:options:error`, and a suggestion as to what may be causing the problem after all.
L Cassarani
A: 

Thanks for helping guys I think we have a winner:

In the log it shows my parsed element returned at the next line instead of flushed with my time code. I never really noticed it before since the url was fitting nicely in my UILabel. And always just thought my url was too long for the log window so it gets pushed to the next line.

I edited my XML with no spaces

<track_title>Sleeping and selling</track_title><consultant_pic>http://localhost:8888/IMAGES/ted.jpg&gt;&lt;/consultant_pic&gt;

Instead of:

<track_title>Sleeping and selling</track_title>
<consultant_pic>http://localhost:8888/IMAGES/ted.jpg&lt;/consultant_pic&gt;
slowman21