iPhone - Replacing rootview in navigation controller(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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:iPhone - 在导航控制器中替换 rootview
基础教程推荐
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
