Search code examples
iosparse-platformpffilepfimageview

fetching 1 image from parse.com


Ive seen many posting on here with phenomenal answers by the community. Unfortunately none have been able to help or guide me to what i need help with. Im trying to "fetch" the image that the "current user" uploaded to parse on the same "UIImageView"

below is the example of how i uploaded the photo

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

    }


}];

}

i honestly have no idea where to go from here! the photo uploads perfectly to the class on parse.com... but i cannot get it to show everytime the app viewdidloads this controller.

i tried

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

but i get unused variable for "image" on UIImage *image = [UIImage imageWithData:data];

what am i doing wrong. Someone please help me with any codes I'm missing. I've been at this for 3 months now and its stopping me from moving forward.... PPPPLLZZZ help


Solution

  • What am I missing? Do you put the image inside an imageView? (thats why you get 'unused variable for "image"')

    in your case:

    [imageView setImage:image];