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

查看:29
本文介绍了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 的事件,我希望它用另一个 rootview 替换该 rootview.下一个就不去了.

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];
}

但这不起作用,第一个视图控制器没有弹出.而第二个则逻辑上用后退按钮显示.

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参考:

这个方法 (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天全站免登陆