1、獲取沙盒路徑
NSString *path_document=NSHomeDirectory();//設(shè)置存儲(chǔ)文件路徑?。。。。?!文件路徑的名字一定要區(qū)分開(kāi) NSString *imagePath=[path_document stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@%@%@.png",_shopObj.shopPicture,_shopObj.shopColor,self.shopObj.shopName]];//寫(xiě)入文件 [UIImagePNGRepresentation(img) writeToFile:imagePath atomically:YES];//將地址存儲(chǔ)到自己設(shè)置的Model模型中 self.shopObj.shopPicture=imagePath;
2、讀取數(shù)據(jù)的時(shí)候,直接從自己設(shè)置文件中讀取出來(lái)就行了,例子如下:
NSString *path_document=NSHomeDirectory(); NSString *imagePath=[path_document stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@%@%@.png",_shopObj.shopPicture,_shopObj.shopColor,self.shopObj.shopName]]; UIImage *img=[UIImage imageWithContentsOfFile:imagePath]; cell.imgV.image=img;
順便說(shuō)一下設(shè)置的根目錄的位置:
2,獲取Documents目錄路徑的方法:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);NSString *docDir = [paths objectAtIndex:0];
3,獲取Caches目錄路徑的方法:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);NSString *cachesDir = [paths objectAtIndex:0];
4,獲取tmp目錄路徑的方法:
NSString *tmpDir = NSTemporaryDirectory();
感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!
新聞熱點(diǎn)
疑難解答
圖片精選