简体   繁体   English

NavigationController正在显示另一个视图控制器,而不是推送ViewController

[英]NavigationController is showing another view controller instead of pushing viewcontroller

I have main ViewController which is named ViewController(if i run my project it runs firstly). 我有一个名为ViewController的主ViewController(如果我运行我的项目,它将首先运行)。 If i push my DetailViewController, it is showing my ViewController view. 如果我按我的DetailViewController,它将显示我的ViewController视图。

Here is my part of code: 这是我的部分代码:

AppDelegate.m AppDelegate.m

ViewController *viewController = [[ViewController alloc] initWithNibName:Nil bundle:nil];
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController];

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

Viewcontroller.m Viewcontroller.m

DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:nil bundle:NULL];
    [self.navigationController pushViewController:detailVC animated:YES];

In your Button's Action, implement this 在“按钮的操作”中实施此操作

DetailViewController *detailVC = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
[self.navigationController pushViewController:detailVC animated:YES];

You are not initializing with its nib file 您尚未使用其nib文件进行初始化

Check following code 检查以下代码

DetailViewController *detailVC = [[DetailViewController alloc] init];
[self.navigationController pushViewController:detailVC animated:YES];

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

相关问题 推送ViewController后,Navigationcontroller被隐藏 - Navigationcontroller is hidden after pushing viewcontroller 旋转父视图控制器,如果从NavigationController呈现一个viewController - Rotating Parent View Controller, if Presenting a viewController from NavigationController ios:在模型视图上推送另一个ViewController - ios: Pushing another ViewController on a model view 导航控制器未推送其他视图 - Navigation controller not pushing another view 具有到另一个视图控制器的tableview的ViewController - ViewController with a tableview to another view controller iOS未将新视图推送到NavigationController - iOS Not Pushing new view to NavigationController 推动Viewcontroller通过导航控制器,显示黑屏 - Pushing Viewcontroller through navigation controller , Showing Black screen 在应用程序启动结束时的root视图控制器,默认为cocos2d viewcontroller而不是另一个Storyboard视图 - root view controller at the end of application launch, defaulting to cocos2d viewcontroller instead of another storyboard view 从嵌入在TabBarController和NavigationController中的ViewController推送新的ViewController - Pushing a new ViewController from a ViewController that is embedded in a TabBarController and NavigationController 推动视图控制器和添加控制器视图有什么区别? - what's the difference between pushing a viewcontroller and adding the controller'view?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM