0

这是我的应用程序代码,我用于选择图像选择器,当图像选择时我想关闭当前视图控制器,因为它在图像选择器本身的关闭时不会从当前视图控制器中关闭,

 -(IBAction)selectExitingPicture
 {
      self.imagePicker = [[GKImagePicker alloc] init];
      self.imagePicker.cropSize = CGSizeMake(296, 300);
      self.imagePicker.delegate = self;
      self.imagePicker.resizeableCropArea = YES;
      [self presentViewController:self.imagePicker.imagePickerController animated:YES completion:nil];
 }
 -(void)imagePicker:(GKImagePicker *)imagePicker pickedImage:(UIImage *)image
 {
      appDel.im=image;
      [self hideImagePicker];
 }
 - (void)hideImagePicker
 {
      [self.imagePicker.imagePickerController dismissViewControllerAnimated:YES completion:^{
                            [self.navigationController pushViewController:viewCont animated:YES ];
                         }];
 }

请帮我解决这个问题,我应该进一步添加什么代码

4

2 回答 2

0

您应该使用这一行来关闭 PickerController :

[self dismissViewControllerAnimated:YES completion:nil];

您可以在两种委托方法中调用此行:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
于 2013-05-15T10:33:35.877 回答
0

.h 文件 int flg;

.m 文件

    viewDidLoad
     flg=0;


  -(void)viewWillAppear:(BOOL)animated {
      [super viewWillAppear:animated];
      if(flg==1) {
           [self dismissViewControllerAnimated:YES completion:nil];
            flg=0;
      }
  }

  - (void)hideImagePicker
   {

       [self.imagePicker.imagePickerController dismissViewControllerAnimated:YES completion:nil];

   }

  - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo{
        self.imgView.image = image;
        flg=1; 
       [picker dismissViewControllerAnimated:YES completion:nil];
   }
于 2013-05-15T10:36:58.437 回答