如何将图像保存在主目录中?
我正在制作一个使用 Json 解析的应用程序。在 json 解析的帮助下,我得到了保存在字符串中的照片 url。为了在我的单元格中显示图像,我使用此代码
NSString *strURL=[NSString stringWithFormat:@"%@", [list_photo objectAtIndex:indexPath.row]];
NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: strURL]];
CGRect myImage =CGRectMake(13,5,50,50);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImage];
[imageView setImage:[UIImage imageWithData: imageData]];
[cell addSubview:imageView];
现在的问题是,当我返回或前进时,我必须等待几秒钟才能返回相同的视图。现在我希望当应用程序第一次使用时我等待该屏幕,否则从主目录获取图像。如何将这些图像保存在我的主目录中?如何从主目录访问?
I am making an application in which i have use Json parsing. With the help of json parsing i get photo url which is saved in string. To show images in my cell i use this code
NSString *strURL=[NSString stringWithFormat:@"%@", [list_photo objectAtIndex:indexPath.row]];
NSData *imageData = [[NSData alloc] initWithContentsOfURL: [NSURL URLWithString: strURL]];
CGRect myImage =CGRectMake(13,5,50,50);
UIImageView *imageView = [[UIImageView alloc] initWithFrame:myImage];
[imageView setImage:[UIImage imageWithData: imageData]];
[cell addSubview:imageView];
Now prblem is that when i go back or forword then i have wait for few second to come back on same view. Now i want that i when application is used first tme then i wait for that screen otherwise get images from home directory. How i save these image in my home directory? How access from home directory?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用 imageData 将图像保存在默认文档目录中,如下所示;
You can save an image in the default documents directory as follows using the imageData;
您可以使用它将文件写入您的文档文件夹
并读取:
You can use this to write a file to your Documents Folder
and this to read: