tags:

views:

87

answers:

1

hi,

if i place a image.png file in my resource, iphone will be able to read it. if i place a image.png file in iphone document folder it doesn't read?

i am sending the image over from my server, into the document folder. no problem with that.

i thought iphone will auto find the image file either in resource folder or document folder?

i did write any code for my app to locate the folder of my image, just called it by its file name, which is correct.

any ideas?

thks

// Get path to doc folder
NSArray *docpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [docpaths objectAtIndex:0];
NSString *docpath = [documentsDirectory stringByAppendingPathComponent:@"Data.plist"];      
self.data = [NSArray arrayWithContentsOfFile:docpath];

done loading the plist from doc folder.

now i go to plist, get the file name and display for cell.

NSDictionary *dataItem = [data objectAtIndex:indexPath.row];
cell.icon = [UIImage imageNamed:[dataItem objectForKey:@"Icon"]];

how can i specifiy the image is in my document folder?

+1  A: 

You can create an UIImage from a file by using imageWithContentsOfFile. However you can not read the file just specifying the name if it is in document folder. You need to get the path of your file. Check this answer to get an idea of how to get the file path of document folder.

-- edit
If your plist contains the file names in document folder, then append the filenames from plist to document folder path to get the full path. Hope it helps.

NSArray *docpaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [docpaths objectAtIndex:0];
NSDictionary *dataItem = [data objectAtIndex:indexPath.row];
NSString *imagePath = [documentsDirectory stringByAppendingPathComponent:[dataItem objectForKey:@"Icon"]];
cell.icon = [UIImage imageWithContentsOfFile:imagePath];
taskinoor
hm.. i can't write the exact file name inside my code as it changes. any suggestion?
Stefan
when you are writing the file in document folder after getting it from server, u obviously know the name. right? u need to save the name somewhere (may be in a variable) and then use it.
taskinoor
Check the edit.
taskinoor
hey i just got it too! thks ya!!
Stefan