title: XCode UIActionSheet image
body: <p>I am creating a <code>UIButton</code> and when the user clicks on it, the camera should pop up and allow the user to take a photo. I decided to add a <code>UIActionSheet</code> which allows the user to choose wether they want to choose a photo from the album, or whether they want to take a photo using the camera. Before I added the action sheet the button worked fine, when the user shaped the photo, the background image of the button was replaced by the photo taken by the <code>UIImagePicker</code>. But after I added the action sheet now the <code>UIButtons</code> image is not being replaced by the images taken from the <code>UIImagePicker</code> or from the users photo library</p>
  
  <p>here is the associated code,</p>
  
  <pre><code>- (void)viewWillAppear:(BOOL)animated {
  [super viewWillAppear:animated];
  self.navigationController.navigationBarHidden = YES;
  [self.navigationItem setHidesBackButton:NO];
  
  [self.usernameField becomeFirstResponder];
  uploadPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
  
  [uploadPhotoButton setImage:[UIImage imageNamed:@"uploadphotoicon"] forState:UIControlStateNormal];
  
  uploadPhotoButton.frame = CGRectMake(0, 0, 80, 80);
  
  uploadPhotoButton.clipsToBounds = YES;
  
  uploadPhotoButton.layer.cornerRadius = 80/2.0f;
  uploadPhotoButton.layer.borderColor = [UIColor colorWithRed:.102 green:.737 blue:.612 alpha:1.0].CGColor;
  uploadPhotoButton.layer.borderWidth = 2.0f;
  
  [self.view addSubview:uploadPhotoButton];
  [uploadPhotoButton setCenter:CGPointMake(160, 128)];
  [uploadPhotoButton addTarget:self action:@selector(uploadPhotoButton:) forControlEvents:UIControlEventTouchUpInside];
  
  
  
  
  
  
   - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
  if (buttonIndex &lt; 2) {
      UIImagePickerController * imagePicker = [[UIImagePickerController alloc] init];
      UIImagePickerControllerSourceType type;
  
      switch (buttonIndex) {
          case 0:
              type = UIImagePickerControllerSourceTypePhotoLibrary;
              break;
          case 1:
              type = UIImagePickerControllerSourceTypeCamera;
              break;
  
          default:
              break;
      }
  
      imagePicker.sourceType = type;
      imagePicker.delegate = self;
  
      [self presentViewController:imagePicker animated:YES completion:^{ }];
  }
  
   }
   - (IBAction)signupDone:(id)sender {
       NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
  
  if ([username length] == 0 || [password length] == 0 /*|| [email length] == 0*/){
      UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Please enter a username, password, and email!" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
       [alertView show];
  }
  else {
      PFUser *newUser = [PFUser user];
      newUser.username = username;
      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, nil];
              [alertView show];
          }
          else {
              [self.navigationController popToRootViewControllerAnimated:YES];
          }
      }];
  
    }
  
  
  
    }
    -(IBAction)uploadPhotoButton:(id)sender {
  
  UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"Select Photo" delegate:self cancelButtonTitle:@"Nevermind" destructiveButtonTitle:nil otherButtonTitles:@"From Library", @"From Camera", nil];
  [sheet showInView:self.view];
  
  
  
    }
  -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
  
  
  uploadPhotoButton = [UIButton buttonWithType:UIButtonTypeCustom];
  
  
  uploadPhotoButton.frame = CGRectMake(0, 0, 80, 80);
  
  uploadPhotoButton.clipsToBounds = YES;
  
  uploadPhotoButton.layer.cornerRadius = 80/2.0f;
  uploadPhotoButton.layer.borderColor = [UIColor colorWithRed:.102 green:.737 blue:.612 alpha:1.0].CGColor;
  uploadPhotoButton.layer.borderWidth = 2.0f;
  
  [self.view addSubview:uploadPhotoButton];
  [uploadPhotoButton setCenter:CGPointMake(160, 128)];
  [uploadPhotoButton addTarget:self action:@selector(uploadPhotoButton:) forControlEvents:UIControlEventTouchUpInside];
  
  
  userImage = [info objectForKey:UIImagePickerControllerEditedImage];
  [uploadPhotoButton setImage:userImage  forState:UIControlStateNormal];
  [self.navigationController dismissViewControllerAnimated:YES completion:NULL];
  
  
  
  [self uploadImage];
  </code></pre>