Search code examples
iosobjective-cmodalviewcontrollerpushviewcontroller

PushViewController in fullscreen


I'd like to know if it's possible to push a ViewController of the NavigationController in full screen without tabbar and navigation bar. My problem is as follow:

My app has a NavigationController embedded in a TabBarController. In the NavController I show a FirstVC with a button to navigate to another VC. Right now I do a modal presentation to show the SecondVC. But in this SecondVC I have a tableview where a button returns a ThirdVC. This ThirdVC needs to have the navigationbar and tabbar of the FirstVC. Maybe I need to show the SecondVC with a push on the NavigationController of the first but it seems that I can't reproduce my full screen animation ...

To make it simple:

FirstVC ===> SecondVC (modal presentation) ====> ThirdVC (modal presentation):

This is my app at this time without navbar or tabbar on the ThirdVC.

Thanks in advance.

Edit

The modal presentation to the SecondVC is like that:

- (IBAction)detailButtonClicked:(id)sender {
    SecondVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondVC"];
    vc.modalPresentationStyle = UIModalPresentationFullScreen;
    [self presentViewController:vc animated:YES completion:nil];
 }

From the SecondVC to the ThirdVC I use again presentViewController because I can't use pushViewController in modal. The result is predictable: I don't have a navigation bar or a tabbar.

I tried different things like the one below or addChildView as subview to my FirstVC:

- (IBAction)detailButtonClicked:(id)sender {
    SecondVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondVC"];
    UINavigationController *childNavigationController = [[UINavigationController alloc] initWithRootViewController:vc];
    childNavigationController.navigationBarHidden = YES;
    [self.navigationController presentViewController:childNavigationController animated:YES completion:nil]; 
}

and in the SecondVC

- (IBAction)changeButtonClicked:(id)sender {
    ThirdVC *vc = [self.storyboard instantiateViewControllerWithIdentifier:@"ThirdVC"];
    [self.navigationController pushViewController:vc animated:YES];
 }

I can't access my tabbar or navigation bar in the ThirdVC either...


Solution

  • What I do in your is I added following code improvement.

    - (IBAction)buttonClicked:(id)sender {
        UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"Main"
                                                                 bundle: nil];
        SecondViewController *vc = (SecondViewController*)[mainStoryboard
                                              instantiateViewControllerWithIdentifier: @"SecondVC"];
        vc.delegate = self;
    
        [[APP_DELEGATE window] addSubview:vc.view];
        [self addChildViewController:vc];
    }
    

    Main line of code is addchildViewController.

    Here You can download the sample code of yours.