1

我有一个基于导航的 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 还没有完全初始化。这可能吗?我怎样才能避免这种情况?

谢谢,马克。

4

1 回答 1

0

是的........这应该是真的......你可以做的事情......像这样......

只需根据您的设置检查条件,它直接来自 RootViewController,然后在 SecondLevelViewController 的导航栏中放置一个自定义后退按钮/条形按钮。

在此之前您需要检查条件...如果是真的使用自定义按钮

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(Back:)];

  • (无效)返回:(id)发件人{

    [self.navigationController popToRootViewControllerAnimated:YES]; }

我想它肯定对你有用。

于 2010-09-20T06:34:30.873 回答