【问题标题】:How to Load Images from Document Directory in iOS8.3+iOS8.3+如何从文档目录加载图片
【发布时间】:2015-08-20 07:50:39
【问题描述】:

iOS8.4 和 Xcode6.4,
注意: 数据库路径:/Library/Developer/CoreSimulator/Devices/FD6CE853-5AE2-48DA-A9B1-E69A6BB4F9F8/data/Containers/Data/Application/BED214A4-65E1-4BD8-9908-29E07FD47EBA/Documents/DB/copybox.db
正在保存时间文件路径:/Library/Developer/CoreSimulator/Devices/FD6CE853-5AE2-48DA-A9B1-E69A6BB4F9F8/data/Containers/Data/Application/BED214A4-65E1-4BD8-9908-29E07FD47EBA/Documents/Images/010521PMThursdayAug2015.png
我想从文档目录加载图片。我尝试了很多方法,如下所示。

NSString*path = [info valueForKey:@"copied_img_path"];
    path = [path stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    path = [NSString stringWithFormat:@"file:/%@",path];//
    NSLog(@"\n##IMAGE PATH##:-%@\n",path);
//Tried with this
    [imageview setImageWithURL:[NSURL fileURLWithPath:path]];
//Tried with this
    NSURL* pathurl = [NSURL URLWithString:path];
    [imageview setImageURL:pathurl];
//Tried with this
    UIImage* image = [UIImage imageWithContentsOfFile:path];
    [imageview setImage: image];


但没有成功。
然后我在将图像保存在文档目录中时检查文件路径。没关系。但是下次我运行此代码时,当前的应用程序文件夹会消失。所以,在 iOS8.3+ 中访问文档目录有任何变化,或者我犯了任何错误。请告诉我。
提前致谢

【问题讨论】:

    标签: objective-c xcode6.4 ios8.4


    【解决方案1】:

    你应该never保存完整路径,路径中的GUID会改变。

    只需请求文档目录的路径,并将图片的相对文件路径添加到该路径即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-27
      • 2022-01-26
      • 2019-01-30
      • 1970-01-01
      • 2014-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多