【问题标题】:UIImageView, Image doesn't load when project is rebuilt [duplicate]UIImageView,重建项目时不加载图像[重复]
【发布时间】:2016-05-24 05:28:29
【问题描述】:

所以我像这样将我的图像保存在我的本地目录中..

NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
                NSString * basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
                UIImage * imageToSave = self.imgViewUser.image;
                NSData * binaryImageData = UIImagePNGRepresentation(imageToSave);

                [binaryImageData writeToFile:
                 [basePath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@.png",self.txtUserName.text ]] atomically:YES] ;

                NSString *final = [NSString stringWithFormat:@"%@/%@.png",basePath,self.txtUserName.text];

[user setValue:final forKey:@"imagePath"];

我正在使用 CoreData 来保存它。然后在将其检索给其他控制器时,我正在这样做..

NSString *imagePath = [self.user valueForKey:@"imagePath"];
UIImage *image = [UIImage imageWithContentsOfFile:imagePath];
self.imgViewUser.image = image;

起初添加我的图像并搜索用户后,我可以看到图像,但是当我重新运行项目时,图像没有加载。帮助! :)

【问题讨论】:

  • 重新运行项目时是否删除之前的构建/更改模拟器操作系统版本?

标签: ios objective-c core-data uiimageview uiimage


【解决方案1】:

我在过去的一个项目中遇到过这个问题。

不要保存完整的图像路径。

您只需要存储图像,每次运行项目时,您只需将“username.png”附加到您的路径。这将适用于每次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-01
    • 2017-02-03
    • 1970-01-01
    • 2016-06-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多