iPhone - 替换导航控制器中的rootview [英] iPhone - Replacing rootview in navigation controller

查看:180
本文介绍了iPhone - 替换导航控制器中的rootview的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有NavigationController的项目,它包含IB中要显示的第一个ViewController。这只是创建项目时的默认模式。

I have a project with a NavigationController, that contains into IB the first ViewController to show. That's just the default pattern when creating the project.

在第一个viewController中,我收到一些我发送到appDelegate的事件,我希望它用以下内容替换另一个。不会去下一个。

In that first viewController, I receive some event that I send to the appDelegate, and I want it to replace that rootview with another one. Not going to a next one.

所以我这样做:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{   
    // Override point for customization after application launch.
    // Add the navigation controller's view to the window and display.
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void) goNext {

    [self.navigationController popViewControllerAnimated:NO];

    NextViewController* nextWindow = [[[NextViewController alloc] initWithNibName:@"NextView" bundle:nil] autorelease];
    [self.navigationController pushViewController:nextWindow animated:NO];
}

但这不起作用,第一个viewcontroller没有poped。
第二个是逻辑显示的,带有后退按钮。

But that doesn't work, the first viewcontroller is not poped. And the second one is logically displayed with a back button.

我只是想用另一个替换第一个视图作为导航过程的开始。

I just want to replace that first view with the other one as the start of the navigation process.

推荐答案

来自 UINavigationController reference


此方法(popViewControllerAnimated :)从堆栈中删除顶视图控制器,并使
成为活动视图控制器的新堆栈顶部。如果堆栈顶部的视图
控制器是根视图控制器,则此
方法不执行任何操作。换句话说,你不能弹出
堆栈上的最后一项。

This method (popViewControllerAnimated:) removes the top view controller from the stack and makes the new top of the stack the active view controller. If the view controller at the top of the stack is the root view controller, this method does nothing. In other words, you cannot pop the last item on the stack.

你可以尝试 setViewControllers:animated:方法。

- (void) goNext {

    NextViewController* nextWindow = [[[NextViewController alloc] initWithNibName:@"NextView" bundle:nil] autorelease];
    [self.navigationController setViewControllers:[NSArray arrayWithObject:detailViewController] animated:YES];
}

这篇关于iPhone - 替换导航控制器中的rootview的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆