UINavigationController 内 UITabBarController 的 popView

发布于 2024-08-31 11:35:21 字数 2187 浏览 7 评论 0原文

我正在基于 Xcode 中的实用程序模板构建一个应用程序,并向其中添加了更多视图。我的应用程序结构如下:

  • MainView(应用程序菜单)

    • 翻转视图(计算器)

    • UINavigationController

    • 设置视图

      • viewDiDLoad:UITabBarController

         - Tab1 视图(选项)
                - Tab2视图(信息文本)
        

我可以从 MainView 正确导航到 Flip-side 视图,这也是导航控制器的根视图。从我的翻转视图中,我推送导航控制器的第二个视图(设置视图),该视图配置为在加载(使用 viewDidLoad)后立即显示带有两个选项卡的 UITabBarController。

如果我删除 UITabBarController,我可以使用“设置”视图中的“popViewController”毫无问题地返回到我的翻转视图。如果我在“设置”视图中的 viewDiDLoad 中加载 UITabBarController,问题就会出现...选项卡工作正常,但我无法再返回到我的翻转视图(导航控制器的根视图)。

如果我使用导航控制器的导航栏,我可以返回,但我想配置自己的按钮并隐藏导航栏。

到目前为止,我已经尝试了以下方法:

  • [self.navigationController popViewControllerAnimated:YES];

  • [self.navigationController popToRootViewControllerAnimated:YES];

  • [self.navigationController popToViewController:FlipSideViewController 动画:是];

但它们似乎不起作用。前两个什么都不做(屏幕保持原样),第三个无法识别“FlipsideViewController”(也许因为它是 MainViewController 的委托?)。

如果我激活导航栏的“后退”按钮,有没有办法检查它到底在做什么?

我应该使用代表吗?

我可以从两个选项卡视图中的任何一个在“设置”视图中调用 popViewController 方法吗?

这是我的另一面视图:

- (IBAction)showSettingsView {
    SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    controller.title = @"Settings";
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

这是我的设置视图:

- (void)viewDidLoad {
    [super viewDidLoad];

    tabBarController = [[UITabBarController alloc] init];

    Tab1ViewController* vc1 = [[Tab1ViewController alloc] init];
    Tab2ViewController* vc2 = [[Tab2ViewController alloc] init];

    NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
    tabBarController.viewControllers = controllers;

    [self.view addSubview:tabBarController.view];
}

以及在选项卡视图之一中返回的方法:

- (IBAction)backFromTab1View {
    [self.navigationController popToViewController:FlipSideViewController animated:YES];
}

非常感谢,如果问题太基本,则表示抱歉!

I'm building an application based on the Utility template from Xcode, to which I have added some more views. My application structure would be as follows:

  • MainView (the app menu)

    • Flip-side view (a calculator)

    • UINavigationController

    • Settings view

      • viewDiDLoad: UITabBarController

                - Tab1 view (options)
                - Tab2 view (information text)
        

I can navigate correctly from my MainView to my Flip-side view, which is also the root view of the Navigation Controller. From my Flip-side view, I push a second view of my Navigation Controller (Settings view) that is configured to show an UITabBarController, with two tabs, as soon as it loads (with viewDidLoad).

If I remove the UITabBarController, I can return with no problems to my Flip-side view using "popViewController" from my Settings view. The problem comes if I load the UITabBarController in viewDiDLoad in my Settings view... the tabs work perfectly, but I'm not able to return to my Flip-side view (root view of the Navigation Controller) anymore.

I CAN return if I use the Navigation Bar of the Navigation Controller, but I want to configure my own buttons and have the Navigation Bar hidden.

So far I've tried the following methods:

  • [self.navigationController popViewControllerAnimated:YES];

  • [self.navigationController popToRootViewControllerAnimated:YES];

  • [self.navigationController popToViewController:FlipSideViewController animated:YES];

But they don't seem to work. The first two just do nothing (the screen remains as it was), and the third one does not recognize the "FlipsideViewController" (maybe because it's a delegate of the MainViewController?).

Is there a way to check what is exactly doing the "back" button of the Navigation Bar if I activate it?

Should I be using delegates?

Can I call a popViewController method in my Settings view from any of the two Tab views?

This is my Flip-side view:

- (IBAction)showSettingsView {
    SettingsViewController *controller = [[SettingsViewController alloc] initWithNibName:@"SettingsView" bundle:nil];
    controller.title = @"Settings";
    [self.navigationController pushViewController:controller animated:YES];
    [controller release];
}

This is my Settings view:

- (void)viewDidLoad {
    [super viewDidLoad];

    tabBarController = [[UITabBarController alloc] init];

    Tab1ViewController* vc1 = [[Tab1ViewController alloc] init];
    Tab2ViewController* vc2 = [[Tab2ViewController alloc] init];

    NSArray* controllers = [NSArray arrayWithObjects:vc1, vc2, nil];
    tabBarController.viewControllers = controllers;

    [self.view addSubview:tabBarController.view];
}

And the method to return in one of the Tab views:

- (IBAction)backFromTab1View {
    [self.navigationController popToViewController:FlipSideViewController animated:YES];
}

Thanks very much and sorry if the question is too basic!

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

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

发布评论

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

评论(1

软糯酥胸 2024-09-07 11:35:21

我实际上解决了在“设置”视图中创建自己的 UINavigationBar 并使用:

[self.view insertSubview:tabBarController.view belowSubview:myNavigationBar];

将视图的其余部分插入导航栏下方的问题,我仍然可以使用它来配置弹出视图并返回到上一个屏幕的按钮。

我花了一段时间才意识到“addSubview”和“inserSubview + BelowSubview”之间的区别。对此感到抱歉!

I actually solved the problem creating my own UINavigationBar in the Settings view and using:

[self.view insertSubview:tabBarController.view belowSubview:myNavigationBar];

That inserts the rest of the view below the Navigation Bar and I still can use it to configure a button which pops the view and return to the previous screen.

It took me a while to realise the differences between "addSubview" and "inserSubview + belowSubview". Sorry about that!

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