title: Adding profile picture at user signup using Parse - iOS
body: <p>I'm trying to create a New User using Parse.com as my backend. I was able to successfully register the user's info. But, my problem is saving the user's profile picture along with it. After the user selects the picture using the camera or photo library, I am presenting an image editor (<a href="https://github.com/heitorfr/ios-image-editor" rel="nofollow">https://github.com/heitorfr/ios-image-editor</a>) using a .xib file. This all works fine with no problems. Then the image is placed in the UIImageView box and the user proceeds to fill in the Username, email and password and they click signup. The problem is after they sign up and all the info gets placed in the table via Parse, the image container seems to be empty. When I click on the image file, the picture is not there. I can't seem to figure out what I'm doing wrong.</p>
  
  <p><strong>View Did Load</strong></p>
  
  <pre><code>- (void)viewDidLoad {
  [super viewDidLoad];
  
  self.addPhotoImageView.contentMode = UIViewContentModeScaleAspectFill;
  
  
  // Create add photo popup
  self.addPhotoActionSheet = [[UIActionSheet alloc] initWithTitle:@"Select source" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Take photo", @"Choose photo", nil];
  
  // Create image picker
  self.imagePicker = [[UIImagePickerController alloc] init];
  self.imagePicker.delegate = self;
  self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
  self.imagePicker.editing = YES;
  }
  </code></pre>
  
  <p><strong>Image Picker Controller Delegate Methods</strong></p>
  
  <pre><code>// Switches to the image editing view
  - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
  [self.imagePicker dismissViewControllerAnimated:NO completion:nil];
  
  if (self.imageEditorViewController == nil) {
  
      self.imageEditorViewController = [[HFImageEditorViewController alloc] initWithNibName:@"ImageEditor" bundle:nil]; }
  
  self.imageEditorViewController.sourceImage = image;
  self.imageEditorViewController.rotateEnabled = NO;
  self.imageEditorViewController.checkBounds = YES;
  [self.imageEditorViewController reset:NO];
  
  
  __weak typeof(self) weakSelf = self;
  self.imageEditorViewController.doneCallback = ^(UIImage *editedImage, BOOL canceled) {
  
      if (!canceled) {
  
          [weakSelf.addPhotoImageView setImage:editedImage];
  
  
      }
      // Hide editor
      [weakSelf.imageEditorViewController dismissViewControllerAnimated:YES completion:nil];
  };
  
  [self presentViewController:self.imageEditorViewController animated:NO completion:nil]; }
  
  - (void) imagePickerControllerDidCancel:(UIImagePickerController *)picker {
  
  [self dismissViewControllerAnimated:YES completion:nil]; }
  </code></pre>
  
  <p><strong>UIActionSheetDelegate methods</strong></p>
  
  <pre><code>-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
  {
  switch (buttonIndex) {
      case 0:
          self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
          break;
  
      case 1:
          self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
          break;
  
      default:
          return;
  }
  
  [self presentViewController:self.imagePicker animated:YES completion:nil]; }
  </code></pre>
  
  <p><strong>Here is IBAction signup code:</strong></p>
  
  <pre><code>- (IBAction)signup:(id)sender {
  
  NSData *imageData = UIImageJPEGRepresentation(self.chosenImage, 0.5f);
  PFFile *imageFile = [PFFile fileWithName:@"Profileimage.jpg" data:imageData];
  
  NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  NSString *email = [self.emailField.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
  NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
  
  if ([username length] == 0 || [email length] == 0 || [password length] == 0) {
      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops" message:@"Make sure you fill in all the fields!" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
  
      [alertView show];
  }
  else {
      PFUser *newUser = [PFUser user];
      newUser[@"ProfilePic"] = imageFile;
      newUser.username = username;
      newUser.email = email;
      newUser.password = password;
  
      [newUser signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
          if (error) {
              UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:[error.userInfo objectForKey:@"error"] delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
  
              [alertView show];
          }
          else {
              [self.navigationController popToRootViewControllerAnimated:YES];
          }
      }];
  
  }
  </code></pre>
  
  <p>}</p>