[英][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. UINavigationController
是controller 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.