从 parse.com 中获取 1 张图像

fetching 1 image from parse.com

我看到这里有很多帖子,社区给出了非凡的答案。不幸的是 none 能够帮助或引导我找到我需要帮助的地方。我正在尝试 "fetch" "current user" 上传的图像以在同一个 "UIImageView"

上解析

以下是我上传照片的示例

myaccount.h

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

- (IBAction)UploadPhoto:(id)sender;
- (IBAction)selectPhoto:(id)sender;

myaccount.m

- (IBAction)UploadPhoto:(UIButton *)sender {

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"];

// Show progress
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
hud.mode = MBProgressHUDModeIndeterminate;
hud.labelText = @"Uploading";
[hud show:YES];

// Upload Profile Picture to Parse
[User saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
    [hud hide:YES];
    if (!error) {
        // Show success message
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Complete" message:@"Successfully uploaded profile picture" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

        // Dismiss the controller
        //[self dismissViewControllerAnimated:YES completion:nil];

    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Upload Failure" message:[error localizedDescription] delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

    }


}];

}

老实说,我不知道从这里去哪里!照片完美上传到 parse.com 上的 class...但是每次应用程序查看并加载此控制器时我都无法显示它。

我试过了

- (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
    }
}];

但是我在 UIImage *image = [UIImage imageWithData:data];

上得到了 "image" 未使用的变量

我做错了什么。有人请帮我解决我遗漏的任何代码。我已经做了 3 个月了,它阻止我前进.... PPPPLLZZZ 帮助

我错过了什么?您是否将图像放在 imageView 中? (这就是为什么你得到 'unused variable for "image"')

你的情况:

[imageView setImage:image];