带导航的dismissViewControllerAnimated问题

时间:2013-05-15 10:28:21

标签: ios uinavigationcontroller presentmodalviewcontroller

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

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

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

2 个答案:

答案 0 :(得分:0)

您应该使用此行来关闭PickerController:

[self dismissViewControllerAnimated:YES completion:nil];

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

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

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

答案 1 :(得分: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];
   }