tags:

views:

41

answers:

1

hi i am new to iphone.What i need is i have to get image through XML parsing and that image is from local folder.I am trying this using this link http://www.iphonesdkarticles.com/2008/11/parsing-xml-files.html. 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 pls post any link related to how to get image from local folder through XML file.Thank you in advance

+1  A: 

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]

vodkhang
i am trying this UIImage *image = [UIImage imageNamed:string];NSLog (@"%@", image);imageView = [[UIImageView alloc] initWithImage:image]; in console i am getting (null) and i need to add image dynamically not manually
MaheshBabu
"Built into the app and while i am giving NSString *strring = @"apple.png"; it will display well", but you said here that it is built into the app and you can test it right?
vodkhang
ya i test it ,it working fine while i am using this NSString *strring = @"apple.png"
MaheshBabu