Ios 从图像选择器返回时如何更改视图控制器?

Ios 从图像选择器返回时如何更改视图控制器?,ios,objective-c,controller,Ios,Objective C,Controller,我正在尝试做一些简单的事情: 从控制器MAViewControllerMenu中,我可以选择现有图片 选择后,我通过取消选取器视图返回MaviewController菜单 返回MAViewControllerMenu后,我想切换到另一个控制器MAViewControllerPictureDisplay,在这里我可以看到在imageView中选择的图像 但是,它不会带我进入下一个视图 以下是MAViewControllerMenu中的代码 MAViewControllerPictureDispla

我正在尝试做一些简单的事情:

  • 从控制器MAViewControllerMenu中,我可以选择现有图片
  • 选择后,我通过取消选取器视图返回MaviewController菜单
  • 返回MAViewControllerMenu后,我想切换到另一个控制器MAViewControllerPictureDisplay,在这里我可以看到在imageView中选择的图像
  • 但是,它不会带我进入下一个视图

    以下是MAViewControllerMenu中的代码

    MAViewControllerPictureDisplay* imageControllerView;
    - (void)viewDidLoad
    {
    
        [super viewDidLoad];
        // Do any additional setup after loading the view.
        //load next page
        imageControllerView = [[self storyboard]     instantiateViewControllerWithIdentifier:@"chosenImageController"];
    }
    
    
    
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
    {
        image = [info objectForKey:UIImagePickerControllerOriginalImage];//Take image from picker
        imageControllerView.image = image;//set it for the next controller's property
        [self dismissViewControllerAnimated:YES completion:^{
        [self.presentingViewController presentModalViewController:imageControllerView
                                                         animated:YES];
    }];
        //NEXT LINE DOESNT WORK
        [self presentViewController:imageControllerView animated:YES completion:nil];//THAT DOESNT WORK
    }
    
    但是,我在我的第一个控制器中设置了一个按钮,单击该按钮后,它会通过下面的函数运行上面的那一行,并且该按钮会将我带到下一个控制器:

    - (IBAction)movetonext{
        [self presentViewController:imageControllerView animated:YES completion:nil];
    }
    
    我遗漏了什么?为什么它在点击按钮时起作用,而在选择图片后在没有触摸事件的情况下起作用

    谢谢

    试试这个:

    而不是弹出UIVIewController,然后显示。按下两个视图控制器,然后弹出一个

    当您呼叫选择器时:

      [self presentViewController:imageControllerView animated:NO completion:nil];
      [self presentViewController:PickerController animated:YES completion:nil];
    
    当你解雇时:

       [Picker dismissViewControllerAnimated:YES completion:NULL];
    
    请注意,当我调用两个UIViewController进行演示时,其中一个(尚未演示的那个)的动画设置为“否”

    希望这有帮助

    编辑

    以上代码仅适用于UINavigationController,通过“PushViewController”和“PopViewController”

    我发现实现这一点的唯一两种方法是:

    1-如果您使用NSNotificationCenter取消middel视图,如下所示:

    不幸的是,对您来说,情况不一样,所以我会考虑使用UINaviationController 对你来说,就是为UIImagePicker使用一个子视图,它会抛弃他的自我

    2-知道这是一种黑客,但它的工作!如果在没有动画的情况下调用middel UIViewController,并从该视图调用图像选择器,则它将工作。您必须将拾取的图像委派回。 我在我的代码中添加了middel UIViewController,使其首次将Alpha设置为0,这样您就不会注意到,他是韩元的演示方式:

    //First UIViewController:
    
    @implementation ViewControllerOne
    - (IBAction)buttonPressed:(id)sender {
    
        ViewControllerTwo *viewTwo = [[ViewControllerTwo alloc]init];
        [self presentViewController:viewTwo animated:NO completion:nil];
    }
    
    //Secound UIViewController:
          @interface ViewControllerTwo ()
           @property (nonatomic) UIImagePickerController *myPicker;
           @end
           @implementation ViewControllerTwo
    
           -(void)viewWillAppear:(BOOL)animated
           {
           //View to alph 0 if this is the first time it displayis:
           if (!self.myPicker) {
             [self.view setAlpha:0];
          }else{
            [self.view setAlpha:1];
           }
          }
          -(void)viewDidAppear:(BOOL)animated{
    
          if (!self.myPicker) {
            self.myPicker = [[UIImagePickerController alloc]init];
            self.myPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            self.myPicker.delegate = self;
            [self presentViewController:self.myPicker animated:YES completion:nil];
          }
          }  
           - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:    (NSDictionary *)info
          {
        [self.myPicker dismissViewControllerAnimated:YES completion:nil];
          }
          - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
          {
        [self.myPicker dismissViewControllerAnimated:YES completion:NO];
          }
          - (IBAction)ButtonTwoClicked:(id)sender {
           [self dismissViewControllerAnimated:YES completion:NO];
         }
    
    试试这个:

    而不是弹出UIVIewController,然后显示。按下两个视图控制器,然后弹出一个

    当您呼叫选择器时:

      [self presentViewController:imageControllerView animated:NO completion:nil];
      [self presentViewController:PickerController animated:YES completion:nil];
    
    当你解雇时:

       [Picker dismissViewControllerAnimated:YES completion:NULL];
    
    请注意,当我调用两个UIViewController进行演示时,其中一个(尚未演示的那个)的动画设置为“否”

    希望这有帮助

    编辑

    以上代码仅适用于UINavigationController,通过“PushViewController”和“PopViewController”

    我发现实现这一点的唯一两种方法是:

    1-如果您使用NSNotificationCenter取消middel视图,如下所示:

    不幸的是,对您来说,情况不一样,所以我会考虑使用UINaviationController 对你来说,就是为UIImagePicker使用一个子视图,它会抛弃他的自我

    2-知道这是一种黑客,但它的工作!如果在没有动画的情况下调用middel UIViewController,并从该视图调用图像选择器,则它将工作。您必须将拾取的图像委派回。 我在我的代码中添加了middel UIViewController,使其首次将Alpha设置为0,这样您就不会注意到,他是韩元的演示方式:

    //First UIViewController:
    
    @implementation ViewControllerOne
    - (IBAction)buttonPressed:(id)sender {
    
        ViewControllerTwo *viewTwo = [[ViewControllerTwo alloc]init];
        [self presentViewController:viewTwo animated:NO completion:nil];
    }
    
    //Secound UIViewController:
          @interface ViewControllerTwo ()
           @property (nonatomic) UIImagePickerController *myPicker;
           @end
           @implementation ViewControllerTwo
    
           -(void)viewWillAppear:(BOOL)animated
           {
           //View to alph 0 if this is the first time it displayis:
           if (!self.myPicker) {
             [self.view setAlpha:0];
          }else{
            [self.view setAlpha:1];
           }
          }
          -(void)viewDidAppear:(BOOL)animated{
    
          if (!self.myPicker) {
            self.myPicker = [[UIImagePickerController alloc]init];
            self.myPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            self.myPicker.delegate = self;
            [self presentViewController:self.myPicker animated:YES completion:nil];
          }
          }  
           - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:    (NSDictionary *)info
          {
        [self.myPicker dismissViewControllerAnimated:YES completion:nil];
          }
          - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
          {
        [self.myPicker dismissViewControllerAnimated:YES completion:NO];
          }
          - (IBAction)ButtonTwoClicked:(id)sender {
           [self dismissViewControllerAnimated:YES completion:NO];
         }
    
    试试这个:

    而不是弹出UIVIewController,然后显示。按下两个视图控制器,然后弹出一个

    当您呼叫选择器时:

      [self presentViewController:imageControllerView animated:NO completion:nil];
      [self presentViewController:PickerController animated:YES completion:nil];
    
    当你解雇时:

       [Picker dismissViewControllerAnimated:YES completion:NULL];
    
    请注意,当我调用两个UIViewController进行演示时,其中一个(尚未演示的那个)的动画设置为“否”

    希望这有帮助

    编辑

    以上代码仅适用于UINavigationController,通过“PushViewController”和“PopViewController”

    我发现实现这一点的唯一两种方法是:

    1-如果您使用NSNotificationCenter取消middel视图,如下所示:

    不幸的是,对您来说,情况不一样,所以我会考虑使用UINaviationController 对你来说,就是为UIImagePicker使用一个子视图,它会抛弃他的自我

    2-知道这是一种黑客,但它的工作!如果在没有动画的情况下调用middel UIViewController,并从该视图调用图像选择器,则它将工作。您必须将拾取的图像委派回。 我在我的代码中添加了middel UIViewController,使其首次将Alpha设置为0,这样您就不会注意到,他是韩元的演示方式:

    //First UIViewController:
    
    @implementation ViewControllerOne
    - (IBAction)buttonPressed:(id)sender {
    
        ViewControllerTwo *viewTwo = [[ViewControllerTwo alloc]init];
        [self presentViewController:viewTwo animated:NO completion:nil];
    }
    
    //Secound UIViewController:
          @interface ViewControllerTwo ()
           @property (nonatomic) UIImagePickerController *myPicker;
           @end
           @implementation ViewControllerTwo
    
           -(void)viewWillAppear:(BOOL)animated
           {
           //View to alph 0 if this is the first time it displayis:
           if (!self.myPicker) {
             [self.view setAlpha:0];
          }else{
            [self.view setAlpha:1];
           }
          }
          -(void)viewDidAppear:(BOOL)animated{
    
          if (!self.myPicker) {
            self.myPicker = [[UIImagePickerController alloc]init];
            self.myPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            self.myPicker.delegate = self;
            [self presentViewController:self.myPicker animated:YES completion:nil];
          }
          }  
           - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:    (NSDictionary *)info
          {
        [self.myPicker dismissViewControllerAnimated:YES completion:nil];
          }
          - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
          {
        [self.myPicker dismissViewControllerAnimated:YES completion:NO];
          }
          - (IBAction)ButtonTwoClicked:(id)sender {
           [self dismissViewControllerAnimated:YES completion:NO];
         }
    
    试试这个:

    而不是弹出UIVIewController,然后显示。按下两个视图控制器,然后弹出一个

    当您呼叫选择器时:

      [self presentViewController:imageControllerView animated:NO completion:nil];
      [self presentViewController:PickerController animated:YES completion:nil];
    
    当你解雇时:

       [Picker dismissViewControllerAnimated:YES completion:NULL];
    
    请注意,当我调用两个UIViewController进行演示时,其中一个(尚未演示的那个)的动画设置为“否”

    希望这有帮助

    编辑

    以上代码仅适用于UINavigationController,通过“PushViewController”和“PopViewController”

    我发现实现这一点的唯一两种方法是:

    1-如果您使用NSNotificationCenter取消middel视图,如下所示:

    不幸的是,对您来说,情况不一样,所以我会考虑使用UINaviationController 对你来说,就是为UIImagePicker使用一个子视图,它会抛弃他的自我

    2-知道这是一种黑客,但它的工作!如果在没有动画的情况下调用middel UIViewController,并从该视图调用图像选择器,则它将工作。您必须将拾取的图像委派回。 我在我的代码中添加了middel UIViewController,使其首次将Alpha设置为0,这样您就不会注意到,他是韩元的演示方式:

    //First UIViewController:
    
    @implementation ViewControllerOne
    - (IBAction)buttonPressed:(id)sender {
    
        ViewControllerTwo *viewTwo = [[ViewControllerTwo alloc]init];
        [self presentViewController:viewTwo animated:NO completion:nil];
    }
    
    //Secound UIViewController:
          @interface ViewControllerTwo ()
           @property (nonatomic) UIImagePickerController *myPicker;
           @end
           @implementation ViewControllerTwo
    
           -(void)viewWillAppear:(BOOL)animated
           {
           //View to alph 0 if this is the first time it displayis:
           if (!self.myPicker) {
             [self.view setAlpha:0];
          }else{
            [self.view setAlpha:1];
           }
          }
          -(void)viewDidAppear:(BOOL)animated{
    
          if (!self.myPicker) {
            self.myPicker = [[UIImagePickerController alloc]init];
            self.myPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
            self.myPicker.delegate = self;
            [self presentViewController:self.myPicker animated:YES completion:nil];
          }
          }  
           - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:    (NSDictionary *)info
          {
        [self.myPicker dismissViewControllerAnimated:YES completion:nil];
          }
          - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
          {
        [self.myPicker dismissViewControllerAnimated:YES completion:NO];
          }
          - (IBAction)ButtonTwoClicked:(id)sender {
           [self dismissViewControllerAnimated:YES completion:NO];
         }
    

    使用
    完成
    处理程序:

    -(void)imagePickerController:(UIImagePickerController *)picker 
                                      didFinishPickingMediaWithInfo:(NSDictionary *)info { 
     [self dismissViewControllerAnimated:YES completion:^{
        image = [info valueForKey:UIImagePickerControllerOriginalImage];
        imageControllerView.image = image;
        [self presentViewController:imageControllerView animated:YES completion:nil];
     }];
    }
    

    演示


    使用
    完成处理程序:

    -(void)imagePickerController:(UIImagePickerController *)picker 
                                      didFinishPickingMediaWithInfo:(NSDictionary *)info { 
     [self dismissViewControllerAnimated:YES completion:^{
        image = [info valueForKey:UIImagePickerControllerOriginalImage];
        imageControllerView.image = image;
        [self presentViewController:imageControllerView animated:YES completion:nil];
     }];
    }
    

    演示