1、获取沙盒路径
?
1
2
3
4
5
6
7
|
NSString *path_document=NSHomeDirectory();
//设置存储文件路径!!!!!!文件路径的名字一定要区分开
NSString *imagePath=[path_document stringByAppendingString:[NSString stringWithFormat:@ "/Documents/%@%@%@.png" ,_shopObj.shopPicture,_shopObj.shopColor,self.shopObj.shopName]];
//写入文件
[UIImagePNGRepresentation(img) writeToFile:imagePath atomically:YES];
//将地址存储到自己设置的Model模型中
self.shopObj.shopPicture=imagePath;
|
2、读取数据的时候,直接从自己设置文件中读取出来就行了,例子如下:
?
1
2
3
4
|
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;
|
顺便说一下设置的根目录的位置:
2,获取Documents目录路径的方法:
?
1
2
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];
|
3,获取Caches目录路径的方法:
?
1
2
|
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];
|
4,获取tmp目录路径的方法:
?
1
|
NSString *tmpDir = NSTemporaryDirectory();
|
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
相关文章
猜你喜欢
- 个人服务器网站搭建:如何选择合适的服务器提供商? 2025-06-10
- ASP.NET自助建站系统中如何实现多语言支持? 2025-06-10
- 64M VPS建站:如何选择最适合的网站建设平台? 2025-06-10
- ASP.NET本地开发时常见的配置错误及解决方法? 2025-06-10
- ASP.NET自助建站系统的数据库备份与恢复操作指南 2025-06-10
TA的动态
- 2025-07-10 怎样使用阿里云的安全工具进行服务器漏洞扫描和修复?
- 2025-07-10 怎样使用命令行工具优化Linux云服务器的Ping性能?
- 2025-07-10 怎样使用Xshell连接华为云服务器,实现高效远程管理?
- 2025-07-10 怎样利用云服务器D盘搭建稳定、高效的网站托管环境?
- 2025-07-10 怎样使用阿里云的安全组功能来增强服务器防火墙的安全性?
快网idc优惠网
QQ交流群
您的支持,是我们最大的动力!
热门文章
-
Win10电脑关机太慢怎么办?Win10电脑快速关机方法教程
2025-05-27 49 -
2025-05-27 19
-
2025-05-27 25
-
2025-05-25 15
-
2025-05-29 48
热门评论