Add child view controller to UINavigationController

后端 未结 3 1197
南笙
南笙 2021-01-31 05:30

I\'m trying to add a child view controller to a UIViewController contained in a UINavigationController with this code:

- (void)buttonTa         


        
3条回答
  •  迷失自我
    2021-01-31 06:01

    In your first view controller, do something like this:

    - (IBAction)buttonClick:(id)sender
    {
        SecondViewController *secondView = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
        UIImage *blurryImage = [UIImage imageNamed:@"foo.jpeg"];
        secondView.imageView.image = blurryImage;
        [self.navigationController addChildViewController:secondView];
        secondView.view.frame = self.navigationController.view.frame;
        [self.navigationController.view addSubview:secondView.view];
    }
    

    Then in your second view controller, add the getter for your imageview:

    -(UIImageView *)imageView
    {
        if( _imageView == nil )
        {
            _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 548)];
            [self.view addSubview:_imageView];
        }
        return _imageView;
    }
    

提交回复
热议问题