Show navigation bar in Child View Controller

I am working on an application in which I have to display several view controllers side by side (split views). To do this, I added the view as the controller of the child view.

PURPOSE: I want to show the navigation bar on one controller of the child view together with the already specified separate navigation panel on the controller of the parent view.

PROBLEM: The navigation bar does not appear on the child view controller.

EDIT: I also set the navigation bar of the parent view controller as hidden, but when the child view controller is called, the navigation bar appears on the parent view controller, not the child view controller.

Code to add a child view controller:

    MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:@"MyChildViewController" bundle:nil];

    [self addChildViewController:childViewController];
    [childViewController.view setFrame:CGRectMake(0.0f, 0.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];
    [self.rightContainerView addSubview:childViewController.view];
    [childViewController didMoveToParentViewController:self];

This code works fine, and the child view controller adds fine. I want to know if this is possible or not?

Thanks in advance.

+4
source share
4 answers

I solved this problem myself as follows:

MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:@"MyChildViewController" bundle:nil];
[childViewController.view setFrame:CGRectMake(0.0f, 0.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];

UINavigationController *childNavController = [[UINavigationController alloc] initWithRootViewController:childViewController];
childNavController.view.frame = childViewController.view.frame;

[self addChildViewController:childNavController];
[self.rightContainerView addSubview:childNavController.view];
[childNavController didMoveToParentViewController:self];

, MyChildViewController, . navigationController navigationController , .

+8

,

enter image description here

:

didFinishLaunchingWithOptions appdelegate.m.

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
ECViewController * ec = [[ECViewController alloc] initWithNibName:@"ECViewController" bundle:nil];
UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:ec];
self.window.rootViewController = navigationController;
[self.window makeKeyAndVisible];
return YES;

Nib (ECViewController), :

1:

2:

3: .

4:

5: , , ECViewController .

nib

. control.click .

( ).

textBox.

, xib iOS7, .

, .

.

 ECViewController1 *v = [[ECViewController1 alloc]initWithNibName:@"ECViewController1" bundle:nil];

    [self.navigationController pushViewController:v animated:YES];

, , - .

+3

y- .

MyChildViewController *childViewController = [[MyChildViewController alloc] initWithNibName:@"MyChildViewController" bundle:nil];

    [self addChildViewController:childViewController];
    [childViewController.view setFrame:CGRectMake(0.0f, 44.0f, self.rightContainerView.frame.size.width, self.rightContainerView.frame.size.height)];
    [self.rightContainerView addSubview:childViewController.view];
    [childViewController didMoveToParentViewController:self];
+1
source

I found the link from stackoverflow, we need to add the navigation bar manually, there is no alternative for this.

-1
source

Source: https://habr.com/ru/post/1535533/


All Articles