Strong Like Bull
Strong Like Bull

Reputation: 11297

How come I am unable to view the image on screen?

-(void)parser:(NSXMLParser *)parser
didEndElement:(NSString *) elementName
 namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName{

    if ([elementName isEqual:@"image"]) {

        NSLog(@"Encoded Data %@",encodedData); //THIS SHOWS UP FINE
        //lets now show image

        UIImage * decodedImage = [[UIImage alloc] initWithData:[Base64 decode:encodedData]];
        [Image setImage:decodedImage]; //WHERE IS THE IMAGE?
        [encodedData release];
        encodedData = nil;
    }   
}

I am using the following library for base 64 decoding. http://imthi.com/blog/programming/iphone-sdk-base64-encode-decode.php

Upvotes: 0

Views: 134

Answers (4)

visakh7
visakh7

Reputation: 26400

-(void)parser:(NSXMLParser *)parser 
didEndElement:(NSString *) elementName
 namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {

    if ([elementName isEqual:@"image"]) {

        NSLog(@"Encoded Data %@",encodedData); //THIS SHOWS UP FINE
        //lets now show image

        UIImage * decodedImage = [[UIImage alloc] initWithData:[Base64 decode:encodedData]];
        [yourImageView setImage:decodedImage]; //WHERE IS THE IMAGE?
        //Make sure that you have the imageView added as subview to your current view.
        [encodedData release];
        encodedData = nil;
        [decodedImage release];
    }   
}

Upvotes: 1

Vaibhav Tekam
Vaibhav Tekam

Reputation: 2344

From the code you have posted, and the extent to which you have elaborated the problem makes it difficult to find any one reason for the code not working. Always try to be as much as clear as you can when you post any questions. Take help of providing the log output, screenshots, so that people here can get exact idea of your question.

I have a doubt about the data that you are getting from the Web Service. But as you say its fine, then as Jenifer said, decoding is the problem. Have you tried printing the description of decoded data?

If its getting decoded, then adding it on the imageView can be a problem. As Roger feels you 'Image' object should not be an instance of UIImageView Class but UIImage class, which is a very silly mistake and I don't feel would be the case.

Can you print the log of NSData you are getting from the encoded data?

Upvotes: 0

Erik B
Erik B

Reputation: 42574

I don't know if you have any control of the server, but I wouldn't put the image data directly in the XML. Why not just put the URL to the image in the XML and then just download the image using that URL?

Also I would recommend using a DOM parser. I usually work with JSON, so I don't know which one is best for XML, but a DOM parser makes your life a lot easier.

Upvotes: 0

Roger
Roger

Reputation: 15813

This is wrong.

[Image setImage:decodedImage]; //WHERE IS THE IMAGE?

What you are probably trying to do is;

[myImageView setImage:decodedImage];

So please post the code where you define your UIImageView*. If you have an instance variable called Image that is so defined, please note that you should not start it with a capital as that implies a class definition, not an ivar.

Upvotes: 1

Related Questions