[self.navigationController pushViewController: ngView animated: YES]; does not work

If i use

NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil]; [self presentViewController:ngView animated:NO completion:nil]; 

above, the controller will go to the NGViewController page.

But if I use this navigation controller

 NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil]; [self.navigationController pushViewController:ngView animated:YES]; 

The controller will be on one page.

Can anyone tell what the problem is.

+4
source share
7 answers

You must use this code

 NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil]; [self presentViewController:ngView animated:NO completion:nil]; 

after you wrote this line when then you want to go to another page using the view controller

 UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:ngView]; [self.navigationController pushViewController:navigationController animated:YES]; 

I hope you solve this problem with this code. Good luck.

+2
source

Perhaps self.navigationController self.navigationController nil is to test it by debugging. Your self view controller is not within the UINavigationController .

+1
source

Now i use this code

  NGViewController *ngView = [[NGViewController alloc]initWithNibName:Nil bundle:Nil]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration: 0.50]; [self presentViewController:ngView animated:NO completion:nil]; 

so that it gives the same effect to others

+1
source

The navigator must have a navigation controller (in the storyboard) for navigation.

 [self.navigationController pushViewController:nextController animated:YES]; 
+1
source

UINavigationController is the controller of controllers , and it is designed to push and pop controllers and manage the hierarchy of your view. And your navigationController property tells you if your NGViewController in UINavigationController's hierarchy; if not (as in this case), the navigationController property returns nil .

0
source

You need to create your own navigation controller, and then try to click view controllers and thereby create a hierarchy of views. I usually suggest the following:

  UINavigationController *navigationController = [[UINavigationController alloc]initWithRootViewController:firstviewController]; [self.window setRootViewController:navigationController]; navigationController.delegate = self; navigationController.navigationBarHidden = YES; 
0
source

you need to declare this in your first controller

 NGViewController *ngView = [[NGViewController alloc]init]; [self.navigationController pushViewController:ngView animated:YES]; 
-2
source

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


All Articles