我使用NSDocumentDirectory保存圖像,每次用戶可以在我的應用程序上的按鈕,點擊保存不同的不同編輯圖像像下面NSDocumentsDirectory如何工作?
-(void)saveImg{
NSData *pngData = UIImagePNGRepresentation(signatureImage);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myPhoto.png"];
[pngData writeToFile:filePath atomically:YES];
}
,我讓我的形象在另一類像
-(void)getMyImg{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsPath = [paths objectAtIndex:0];
NSString *filePath = [documentsPath stringByAppendingPathComponent:@"myPhoto.png"];
NSData *pngData = [NSData dataWithContentsOfFile:filePath];
UIImage *myImage = [UIImage imageWithData:pngData];
imgView.image = myImage;
}
我的問題是使用應用程序的文件目錄會導致內存問題?好比說如果我點擊我的saveImg方法超過100倍則是有100圖像在我的應用程序DocumentDirectory或在每次調用先前保存的設置圖像被替換新的(因爲我給同名myPhoto.png),文檔目錄的工作原理是什麼?
任何幫助提前感謝。