如何在基于导航的 iPhone 应用程序启动时跳转到第二级 viewController

发布于 2024-09-17 17:48:42 字数 1204 浏览 5 评论 0原文

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

谢谢, 标记。

I have a navigation based iPhone app.
Normally you start on the RootViewController, there you can select a row from an UITableView which brings you to another ViewController, let's call it SecondLevelViewController.

When the app is started I check if it was quit from SecondLevelViewController (via a parameter saved to the defaultUserSettings). If it was, I want to display that SecondLevelViewController again.

To achieve this I do the check in my application delegates

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

method, right after

[window addSubview:[navigationController view]];
[window makeKeyAndVisible];

Then I add the SecondLevelViewController to the view stack. I tried it with pushViewController and with setViewControllers:

        SecondLevelViewController *newVC = [[SecondLevelViewController alloc] initWithNibName:@"SecondLevelView" bundle:nil];            
        [self.navigationController setViewControllers:[NSArray arrayWithObjects:[self.navigationController.viewControllers objectAtIndex:0], newVC, nil]
                                             animated:YES];

The app then shows the desired view.
Now the problem: the SecondLevelViewController displays a back button on the left side of the navigation bar. This button doesn't appear when using the way described above.
My conclusion is, that the RootViewController isn't yet fully initialized at the time I go the the SecondLevelViewController. Is this possible? How can I avoid this?

Thanks,
Mark.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

太傻旳人生 2024-09-24 17:48:42

是的……应该是真的……
您可以这样做...就像这样...

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

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

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

  • (void)返回:(id)发件人{

    [self.navigationController popToRootViewControllerAnimated:YES];
    }

这肯定对你有用。

Yes .......It's suppose to be true.....
You can do the thing...like this..

Just check the condition as per your setting and it's directly coming from RootViewController then put a Custom Back Button/Bar Button in navigation bar.....of SecondLevelViewController.

Before this You need to check the condition... if it's true use use custom button

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

  • (void) Back: (id) sender{

    [self.navigationController popToRootViewControllerAnimated:YES];
    }

I think so it would definitely work for u.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文