我有一个基于导航的 iPhone 应用程序。通常你从 RootViewController 开始,在那里你可以从 UITableView 中选择一行,这会将你带到另一个 ViewController,我们称之为 SecondLevelViewController。
当应用程序启动时,我检查它是否从 SecondLevelViewController 退出(通过保存到 defaultUserSettings 的参数)。如果是,我想再次显示那个 SecondLevelViewController。
为了实现这一点,我在我的应用程序代表中进行检查
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
方法,紧接着
[window addSubview:[navigationController view]];
[window makeKeyAndVisible];
然后我将 SecondLevelViewController 添加到视图堆栈。我用 pushViewController 和 setViewControllers 试过了:
SecondLevelViewController *newVC = [[SecondLevelViewController alloc] initWithNibName:@"SecondLevelView" bundle:nil];
[self.navigationController setViewControllers:[NSArray arrayWithObjects:[self.navigationController.viewControllers objectAtIndex:0], newVC, nil]
animated:YES];
该应用程序然后显示所需的视图。现在的问题是:SecondLevelViewController 在导航栏的左侧显示一个后退按钮。使用上述方式时,不会出现此按钮。我的结论是,当我进入 SecondLevelViewController 时,RootViewController 还没有完全初始化。这可能吗?我怎样才能避免这种情况?
谢谢,马克。