NavigationController显示另一个视图控制器而不是推送viewcontroller

时间:2014-03-06 11:55:34

标签: ios objective-c uinavigationcontroller

我有一个名为ViewController的主ViewController(如果我运行我的项目,它首先运行)。如果我按下我的DetailViewController,它会显示我的ViewController视图。

以下是我的代码部分:

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

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

2 个答案:

答案 0 :(得分:0)

在Button的动作中,实现此

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

您没有使用其nib文件初始化

答案 1 :(得分:0)

检查以下代码

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