Как сделать так, чтобы UIImagePickerController работал под переключателем UIActionSheet - PullRequest
0 голосов
/ 08 января 2011
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
 UIImage *tempImage = [info objectForKey:UIImagePickerControllerOriginalImage];
 imgview.image = tempImage;
 [self dismissModalViewControllerAnimated:YES];
 [picker release];
}

-(void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
 [self dismissModalViewControllerAnimated:YES];
 [picker release];
}


-(IBAction) calllib
{
 img1 = [[UIImagePickerController alloc] init];
 img1.delegate = self;
 img1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
 [self presentModalViewController:img1 animated:YES];

}

all the codes above works well for taking out photos from the photo library.
problem is that when i tried to use it under the UIActionSheet it does not work.
i just copy the lines of codes from the -(IBAction) calllib as follow.


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
 UIImage *detectface = [Utilities detectFace:imgview.image];
 UIImage *grayscale = [Utilities grayscaleImage:imgview.image];
 UIImage *avatars = [Utilities avatars:imgview.image];

 img1 = [[UIImagePickerController alloc] init];
 img1.delegate = self;
 img1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

 switch (buttonIndex)
 {
  case 0:
   [self presentModalViewController:img1 animated:YES];
   imgview.image = detectface;
   break;
  case 1:
   [self presentModalViewController:img1 animated:YES];
   imgview.image = grayscale;
   break;
  case 2:
   [self presentModalViewController:img1 animated:YES];
   imgview.image = avatars;
   break;

  default:
   break;
 }

}

это не работает. Может кто-нибудь помочь мне разобраться в чем проблема?

корпус переключателя работает отлично без [self presentModalViewController: img1 animated: YES]; ...

спасибо

1 Ответ

0 голосов
/ 08 января 2011
 img1 = [[UIImagePickerController alloc] init];
 img1.delegate = self;
 img1.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

 switch () {
   case 0:
    [self presentModalViewController:img1 animation:YES];
 }

 – (void)imagePickerController:didFinishPickingMediaWithInfo:(NSDictionary *)dict {
    UIImage *image = [dict objectForKey:SOME_KEY_HERE];
    imageView.image = [Utilities detectFace:image];

 }

вам необходимо вызвать обнаружение лица после получения изображения, что означает в методе делегата, возвращенном из UIImagePickerController

...