从parse.com获取1张图片

时间:2015-04-06 05:26:25

标签: ios parse-platform pffile pfimageview

我在这里看过很多帖子,社区都有非凡的答案。不幸的是,没有人能够帮助或指导我需要帮助。我试图"获取" "当前用户"的图像上传解析同一个" 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上的课程...但我不能让它每次都显示应用程序viewdidloads这个控制器。

我试过

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

但是我得到了未使用的变量" image"在UIImage * image = [UIImage imageWithData:data];

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

1 个答案:

答案 0 :(得分:0)

我错过了什么?你把图像放在imageView中吗? (这就是为什么你得到"未使用的变量"图像"')

在你的情况下:

[imageView setImage:image];