0

Thanks to the help of @stee i was able to get the image to upload to the right class in parse.com. Now i can't get it to display that same image in the same uiimageview i used to upload .

with the help of @stee and @Joey i was able to add the code below to my viewdidload. Now i get a warning saying unused variable for the *image and when i compile and run i can upload but as soon as i leave that controller, the image won't be there.

- (void)viewDidLoad {
[super viewDidLoad];

PFFile * myPFFile = [[PFUser currentUser] objectForKey:@"ProfilePicture"];
[myPFFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
    if (!error) {
        UIImage *image = [UIImage imageWithData:data];
        // image can now be set on a UIImageView
    }
}];
}

if it helps you understand what I've done, below is the code i used to upload the photo

PFObject *User = [PFUser currentUser];
NSData *imageData = UIImageJPEGRepresentation(_imageView.image, 0.8);
NSString *filename = [NSString stringWithFormat:@"%@.png", _username.text];
PFFile *imageFile = [PFFile fileWithName:filename data:imageData];
[User setObject:imageFile forKey:@"ProfilePicture"];

is there anything that I'm missing from my viewdidload? am i missing anything from my .h file?

in my .h file i have that uiimageview like;

@property (strong, nonatomic) IBOutlet UIImageView *imageView;

i would greatly appreciate any further help in making this possible.

4

2 回答 2

0

在上传时将图像保存给用户后,可以通过 [User objectForKey:@"ProfilePicture"] 将其作为 PFFile 访问;然后,您将使用 PFFile loadInBackground 函数之一在图像视图上设置图像。

我在您的代码的其他地方也发现了一个问题,您将图像保存到的用户每次都是新的 PFUser。替换 [PFObject objectWithClassName:@"User"]; 与 [PFUser 当前用户];

于 2015-02-11T15:55:30.723 回答
0

每次您在控制器中“viewDidLoad”时,您都可以将选择的图像保存到磁盘或从 Parse 请求用户配置文件。

使用将图像保存到磁盘可以[_imageView.image writeToFile:myFilePath atomically:YES];节省您发出网络请求的时间,但如果用户可以使用应用程序以外的方法更改图片,这可能不是最佳选择。

关于每次请求图像,您可以在[PFUser currentUser]. 完成 fetch 后,您可以获取PFFile *filefrom [PFUser currentUser]["ProfilePicture"]。从 PFUser 获得 PFFile 后,您可以继续转换它:

[myPFFile getDataInBackgroundWithBlock:^(NSData *data, NSError *error) {
  if (!error) {
    UIImage *image = [UIImage imageWithData:data];
    // image can now be set on a UIImageView    
  }
}];

那是我可以用你给我的信息解释它的最好方法!

于 2015-02-11T16:10:16.467 回答