UINavigationController Does Not Show Root View Controller

I have a UIView (menuView in the code below) of size 320x218 inside the view. I want to load the navigation controller into this view. Im using the following code to do this:

MenuViewController *menuController = [[MenuViewController alloc] initWithNibName:@"MenuViewController" bundle:nil];

UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:menuController];
navigationController.navigationBarHidden = YES;

[menuView addSubview:navigationController.view];
[menuController release];
[navigationController release];

When I execute it, the root view is not displayed in this view. Only the navigation bar is displayed, and the rest of the image is empty.

Edit:

I just put NSLog () in initWithNibName: and viewDidLoad: from MenuViewController. One in initWithNibName: is called, but one in viewDidLoad: is not: S

Update:

I tried to click menuControlleron my thinking navigationController, as it does not appear, perhaps it is not on the stack. An exception:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Pushing the same view controller instance more than once is not supported
+2
4

:

UIViewController -viewDidLoad

-initWithRootViewController, . :

navigationController.navigationBarHidden = YES;
[navigationController setView:menuController.view];
+3

layoutsubviews .

[super loadView];
[self.view addSubview:navigationController.view];
[navigationController.view layoutSubviews];
+8

navigationViewController MenuViewController. navigationViewController MenuViewController.

navigationViewController.

0
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.

ViewController *viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease];

navController = [[UINavigationController alloc]initWithRootViewController:viewController];

self.window.rootViewController = self.navController;

appdelegate

0

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


All Articles