0

I'll give an overview of what I am trying to achieve:

1) There is screen1 on which there is a header on navigation bar.

enter image description here

2) On a button click, I am adding screen2 (it doesn't have a nav bar) as a child view controller on the first screen

Code for presenting screen2 upon a button click in screen1

Screen2ViewController *controller = [Screen2ViewController controllerStoryboard:STORYBOARD_NAME];
[self.navigationController addChildViewController:controller];
[controller viewWillAppear:YES];

On screen 2, there is a transparent view (yellow color) on the top which comes above the header of screen 1. enter image description here

3) Screen2 again presents a child view controller (Screen3ViewController - doesn't have a nav bar) which contains the table. (This was the requirement as there are 2 tabs - hidden - which need to show different controllers when tapped)

 Screen3ViewController *fp = [Screen3ViewController controllerStoryboard:STORYBOARD_NAME];
[self addChildViewController:fp];
[self.controllerView addSubview:fp.view];
[fp didMoveToParentViewController:self];

4) When clicked on tableviewcell, screen4 appears which has a nav bar.

enter image description here

Problem - when I click on the cross button of screen4's nav bar, the screen gets popped as expected but the old view distorts a little. The start of screen2 shifts below by 50 pixels from the nav bar bottom of screen1. I am confused what is causing this behavior. Is it because some controllers have nab bar and some don't?

enter image description here

I tried a dirty hack of which I am not proud of (its not working as well)

Code for pushing screen4 when a cell is pressed on screen3

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    Screen3ViewController *mController = [Screen3ViewController controllerStoryboard:STORYBOARD_NAME2];
    mController.media = media;
    [self.navigationController pushViewController:mController animated:YES];
}

back button click

- (void) goback: (id) sender {
[self.navigationController popViewControllerAnimated:YES];
}

EDIT:

Screen shot of storyboard

Screen2: I have hidden some part of text. Those are 2 tabs. And the huge space below is for adding the 3rd view controller

enter image description here

Screen3: It contains a table view

enter image description here

Screen4:

enter image description here

Screen1 and screen4 extend a CustomNavController with code:

@implementation CustomNavController

- (void)viewDidLoad {
[super viewDidLoad];
self.navigationController.navigationBar.layer.shadowOpacity = 0.1;
self.navigationController.navigationBar.layer.shadowRadius = 2;
self.navigationController.navigationBar.layer.shadowOffset = CGSizeMake(0, 2);
self.navigationController.navigationBar.layer.shadowColor = UIColorFromRGB(0).CGColor;

}

On the other hand, screen2 and screen3 directly extend UIViewController

A_G
  • 2,260
  • 3
  • 23
  • 56

0 Answers0