tags:

views:

30

answers:

2

hi i am new to iPhone.what i need is i have to get images from XML file.For that what i did is creating a XML file with code as fallows

<?xml version="1.0" encoding="UTF-8"?>
<Allcategory>
<image>parrot.jpg</image>
</Allcategory>

And i am adding the image in local folder and calling the image in my class for that i am write the code as fallows.

XMLAppDelegate *appdelegate = (XMLAppDelegate *)[[UIApplication SharedApplication]delegate];

Book *abook = [appdelegate.books objectAtindex:0];
NSLog("image %@",abook.image);

here i am getting the image:parrot.jpg in console. but i get null value in UIImage for that i am writing the code as fallows

UIImage *image = [[UIImage imageNamed:abook.image];
NSLog("image %@",abook.image);

here i am getting in console as image (null). what is the wrong,really i dont know how to get image and how display image in imageview that image is get from xml file. pls help me.thank u in advance.

A: 

In the below part i.e

UIImage *image = [[UIImage imageNamed:abook.image];
NSLog("image %@",image);

image is UIImage and not text So its not gonna display anything. what i suggest is you take an imageView and set its frame somewhere on the screen and set imageView.image=image and try to display it on screen. May be you will get the image.

hAPPY cODING...

Suriya
i am trying like this also taking an imageview and displaying the image by writing the code imageView.image = [UIImage imageNamed:abook.image]; but it displays nothing
MaheshBabu
have you set the frame of the imageview over there???? Please post some code to get your actual problem...
Suriya
ya i am trying to display without XML sheet means imageView.image=[UIImage imageNamed:@"parrot.jpg"]; it displays well.
MaheshBabu
can anyone tell me the reason for downVote?
Suriya
A: 

Where are the images stored? [UIImage imageNamed] is meant to return an image that is stored in your application's bundle (meaning it needs to be in the left column of Xcode). If you are trying to load an image from a URL, the code needs to be something like this:

[UIImage imageWithData:[NSData dataWithContentsOfURL:@"http://path/to/image"]];

Ash White
ya i am stored image inmy application's bundle,I need to get image from there it self.
MaheshBabu