2012-09-20 32 views

回答

3

如果你正在保存一些圖像,我建議將圖像保存到文件系統中,而不是將它們保存到NSUserDefaults(或CoreData),然後將文件名保存到NSUserDefaults。

這樣就沒有必要擔心任何容量限制。

保存圖像:

UIImage* image = [UIImage imageNamed:@"example_image.png"]; 
NSData* imageData = UIImageJPEGRepresentation(image, 1.0); 
NSString* imagePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"/saved_example_image.png"]; 
[imageData writeToFile:imagePath atomically:YES]; 

檢索圖像:

NSString* imagePath = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"/saved_example_image.png"]; 
UIImage* imageFromFileSystem = [UIImage imageWithContentsOfFile:imagePath]; 
+0

雖然它可能是有益的,它不是被要求的問題的答案。 – nmdias