Mahesh Babu
Mahesh Babu

Reputation: 3433

How can I get image from local folder through XML file

I am new to iPhone. What I need is I have to get image through XML parsing and that image is from local folder. What I am doing is store the name of the images in the XML and fetch the name accordingly... it gets name but image is not displayed is there any necessity of converting image string name to bitmap code or anything. My code is as fallows.

    <?xml version="1.0" encoding="UTF-8"?>
    <kids>
    <image>apple.png</image>
    </kids> 

Kids*obj = [appdelegate.kids objectAtindex:0];
NSLog("image %@",obj.image);

NSString *strring = obj.image;
imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:string]];

Here I am getting image string name in console as Apple.png but it did n't display image in imageview is there anything wrong. If any thing wrong please post any link related to how to get image from local folder through XML file.

Upvotes: 1

Views: 1139

Answers (1)

vodkhang
vodkhang

Reputation: 18741

Here is some tips and check:

1/ Separate this line out :

imageview = [[UIImageView alloc]initWithImage:[UIImage imageNamed:string]];

to 2 lines:

UIImage *image = [UIImage imageNamed:string];
NSLog (@"%@", image);
imageView = [[UIImageView alloc] initWithImage:image];

then see what the log tells you

2/ What do you mean by local folder. This can be understood in 2 ways:

  • The image is in your project target by you add it in using XCode. If it is this case, manually call UIImage *image = [UIImage imageNamed:@"apple.png"]; to see what returns

  • The image is in your Tmp or /Library folder and you return the file path. Then you cannot use [UIImage imageNamed:FILE_PATH] anymore. You have to call using [UIImage imageWithContentsOfFile:FILE_PATH]

Upvotes: 1

Related Questions