【发布时间】:2014-10-20 06:24:01
【问题描述】:
我有一个使用 UINavigationController 的 iPhone 应用程序,它是这样创建的:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Create navigation controller and initialize it with the menu view controller.
navigationController = [[UINavigationController alloc] initWithRootViewController:[[MenuViewController alloc] init]];
navigationController.navigationBar.hidden = YES;
navigationController.toolbar.hidden = YES;
// Create main window and initialize it with navigation view controller.
window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
[window setRootViewController:navigationController];
[window makeKeyAndVisible];
return YES;
}
从那里开始,事情通常会按类似于以下的顺序发生:
- 推送
SelectDifficultyViewController - 推送
GameViewController - 推送
GameOverViewController - 弹出到根目录 (
MenuViewController)
我将如何切换到GameViewController 的新实例,而不是在第 4 步中弹出到根目录。
我目前有以下内容,但它只是让我回到根目录:
[self.navigationController popToRootViewControllerAnimated:NO];
[self.navigationController pushViewController:[[GameViewController alloc] initWithStuff:stuff] animated:NO];
【问题讨论】:
-
我不确定我是否理解正确...你为什么不在第 4 步推送另一个
GameViewController实例 -
而不是弹出和推送?因为我认为最好不要用大量的视图控制器弄乱堆栈。这个想法是有一个“再次播放”按钮,因此用户有可能多次按下它。
-
我明白你在说什么......有道理。不如只在第 4 步弹出一次,然后从
GameOverViewController返回到GameViewController -
我需要一个不同的
GameViewController实例。init方法比较复杂,为了简洁,我省略了细节。
标签: ios objective-c cocoa-touch uiviewcontroller uinavigationcontroller