0

I don't know if the title explains the question itself but here it is ...

I have a UINavigationController which is the parentViewController of a UINavigationController. The thing is the childViewController behaves strange, when I add it as a child it first has the gap for the statusBar (it doesn't occupy the entire screen) and if I "solve" that "bug" by hiding and showing the navigationBar, the gap goes away but now the child doesn't respect the frame I set manually. Then I tried to continue and when I presented a modal on the child and dismiss it, the entire child goes away ...

What would be wrong there? The parent-child relationship with both containers or what?

Thanks in advice

EDIT: Here's an example project showing the strange behavior

http://www.mediafire.com/?8saa68daqfkf335

EDIT 2: I found a solution actually and I didn't find it really clear on Apple Docs, it says the childViewControllers take its frame from the parentViewController they belong to, but it doesn't say that if the parentViewController "reappears" (like a push on it) the childViewControllers get resized again by the parentViewController frame ... Hope this helps anyone

Herz Rod
  • 831
  • 8
  • 21
  • maybe you can provide a screenshot (or two,...) – mr.VVoo Mar 22 '13 at 14:23
  • Ok give me a sec ... EDIT: Well I can actually only post an image of the gap of the UINavigationController being the child, but the other behavior can't be screenshotted like that ... Let me attach an example project which shows the "bug" thing ... – Herz Rod Mar 22 '13 at 14:24
  • Container inside container, I think this is not a good approach, maybe you need to try a custom controller inside the parent navigation controller... P.S. chupili – D33pN16h7 Mar 22 '13 at 16:38

1 Answers1

0

I believe it would be better to present the second navigation view controller as a modal view controller. For example, replace your current presentController selector with something like:

- (void)presentController:(id)sender {

ChildViewController1 *cvc = [[ChildViewController1 alloc] initWithNibName:@"ChildViewController1" bundle:nil];
nc3 = [[UINavigationController alloc] initWithRootViewController:cvc];

nc3.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

[self presentViewController:nc3 animated:YES completion:nil];

UIBarButtonItem *i = [[UIBarButtonItem alloc] initWithTitle:@"X" style:UIBarButtonItemStyleBordered target:self action:@selector(close)];
cvc.navigationItem.leftBarButtonItem = i;
}

Then, your close selector could become:

- (void)close {
[nc3 dismissViewControllerAnimated:YES completion:nil];
}

(though I'd recommend moving the creation of the button and handling the close actually in ChildViewController1.m).

Of course, this would take all the creation of the navigation controller off ViewController.m's viewDidLoad selector:

- (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blueColor];

UIButton *b = [UIButton buttonWithType:UIButtonTypeRoundedRect];
b.frame = CGRectMake(0, 100, 100, 40);
[b setTitle:@"present" forState:UIControlStateNormal];
[b addTarget:self action:@selector(presentController:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:b];
}

Hope it works!

Pablo
  • 613
  • 5
  • 12
  • The thing is I need the childViewController to always be there because it has a UIPanGestureRecognizer that let you slide the controller to the top to present it ... – Herz Rod Mar 22 '13 at 16:23
  • I agree with D33pN16h7, a UINavigationController inside the rootViewController of another UINavigationController doesn't sound like the best approach. Maybe you can take screenshots of the second navigation controller to present and use that screenshot for the sliding motion, then when the slide is complete you can present your secondary navigation controller without an animation? You'd preserve the illusion while avoiding the nesting of UINavigationControllers. – Pablo Mar 22 '13 at 18:50