HurkNburkS
HurkNburkS

Reputation: 5510

view error with Navigation controller thats inside another Navigation Controller

I have added a navigation controller inside a viewcontroller thats inside another navigation controller... lol

well anyway because of this structure I have an issue with any views I push to the "sub"navigation controller.. because its only fitting inside the grame of the "parent" navigation controller its pushing the pushed views contents down by about 20/40pxl...

I was wondering how I get stop this from happening.. here are two pictures showing you what is happening.

enter image description here

where the label is clearly centered in Interface builder

enter image description here

This is the code I have so far for this stuff.

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    // Init the (sub)navigationController
    otherNav = [[UINavigationController alloc] init];
    // Add this (sub)NavController to the current viewcontroller (which is inside the (parent)navcontroller)
    [self.view addSubview:otherNav.view];
    // Hide the (sub)NavControllerbar
    otherNav.navigationBar.hidden = YES;

    // Load a detial view into the (sub)NavController
    DetailViewController *detailView = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:[NSBundle mainBundle]];
    [otherNav pushViewController:detailView animated:NO];
}

The otherNav is also set up in the .h file for global access in this view.

Upvotes: 0

Views: 150

Answers (1)

yunas
yunas

Reputation: 4163

When the "super" NavigationBar is visible, the self.view.frame.height is:

  • 480-20-44 (actualViewheight-statusbarheight-navigationBarheight).

There are 2 solutions for your problem.

1. For simplicity I would say, if your only problem is to make it centralized.

    [self.view addSubview:otherNav.view];
    [otherNav.view setCenter:self.view.center];

This will make your label center alligned.

2.Though, if you are using interface builder;

  1. select the xib file.
  2. select the view.
  3. open Utilities.
  4. set the Top bar as Navigation bar.

then the things you will align you will get as it is on device/simulator or what ever you are testing on.

Upvotes: 1

Related Questions