简体   繁体   English

[self.navigationController pushViewController:ngView animated:YES]; 不工作

[英][self.navigationController pushViewController:ngView animated:YES]; not working

If i use 如果我使用

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

above code the controller will go to NGViewController page. 上面的代码控制器将转到NGViewController页面。

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 in same page. 控制器将在同一页面中。

Can any one tell that what's the problem. 任何人都可以说出问题是什么。

You should use this code 您应该使用此代码

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

after writting this line when then you you want go on different page with push view controller 写完这一行后,你想要用推视控制器进入不同的页面

UINavigationController *navigationController = [[UINavigationController       alloc]initWithRootViewController:ngView];

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

I hope you will solve this issue by this code Good luck 我希望你能用这段代码解决这个问题祝你好运

Your self.navigationController is probably nil - check it out through debugging. 你的self.navigationController可能是nil - 通过调试检查出来。 Your self view controller is not within a UINavigationController . 您的self视图控制器不在UINavigationController

Now im using 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 wil give same effect other 这样它就会产生同样的效果

自控器应具有导航控制器(在故事板中)以便导航。

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

UINavigationController is a controller of controllers and it is designed to allow you to push and pop controllers and manage a hierarchy of your view's. UINavigationControllercontroller of controllers ,它旨在允许您push and pop controllers并管理视图的层次结构。 And your navigationController property tells you whether your NGViewController is currently in a UINavigationController's hierarchy; 您的navigationController属性会告诉您NGViewController当前是否在UINavigationController's层次结构中; if not (as in this case), the navigationController property returns nil . 如果不是(如本例所示),则navigationController属性返回nil

You have to create your own navigation controller and then try to push the view controllers and thus build up a view hierarchy. 您必须创建自己的导航控制器,然后尝试推送视图控制器,从而构建视图层次结构。 I normally would suggest this: 我通常会建议这样:

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

you need to declare this in your first controller 你需要在你的第一个控制器中声明这个

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 self.navigationController pushViewController 不工作 - self.navigationController pushViewController not working self.navigationController?.pushViewController 不工作 Swift - self.navigationController?.pushViewController not Working Swift self.navigationController pushViewController:动画:给我一个黑屏 - self.navigationController pushViewController: animated: gives me a black screen 使用 self.navigationController 时出现问题?.pushViewController(newViewController, animated: true) - Problems using self.navigationController?.pushViewController(newViewController, animated: true) iOS-[self.navigationController setToolbarHidden:YES动画:NO]崩溃 - iOS - Crash on [self.navigationController setToolbarHidden:YES animated:NO] Deallocated error iOS / iPhone didSelectRowAtIndexPath self.navigationController pushViewController不起作用 - iOS/iPhone didSelectRowAtIndexPath self.navigationController pushViewController not working self.navigationController pushViewController未将控制器添加到堆栈 - self.navigationController pushViewController not adding controller to stack 关于self.navigationController pushViewController(IOS) - about self.navigationController pushViewController (IOS) iOS-调用方法:[self.navigationController pushViewController:animated:],屏幕变黑 - iOS - call the method : [self.navigationController pushViewController: animated:], the screen get whole black 为什么不'self.navigationController?.pushViewController(mainPage,animated:true)'工作? - Why doesn’t 'self.navigationController?.pushViewController(mainPage, animated: true)' work?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM