gpt4 book ai didi

iPhone - 替换导航 Controller 中的 rootview

转载 作者:行者123 更新时间:2023-12-03 18:12:47 24 4
gpt4 key购买 nike

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

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

所以我这样做:

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

但这不起作用,第一个 View Controller 未弹出。第二个逻辑上显示有后退按钮。

我只想将第一个 View 替换为另一个 View ,作为导航过程的开始。

最佳答案

来自UINavigationController reference :

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 - 替换导航 Controller 中的 rootview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6717260/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com