gpt4 book ai didi

iphone - 子类化 UINavigationController 以在 View 之间进行自定义导航

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:44:13 24 4
gpt4 key购买 nike

我正在使用 UINavigationController 制作一个具有以下 View 层次结构的小应用程序:

Login -> Options -> three different views

问题是我想按以下方式在最后 3 个 View 之间导航:

1<->2
1<->3
2<->3

即能够从任何其他 View 切换到任何 View ,这提醒了 UITabViewController 功能。因此,它不是分层的,它是任意对任意图。要在 View 之间切换,我将使用导航栏中的按钮。

对我来说最简单的方法是子类化 UINavigationController,添加对应于我的 View 的属性并实现在这些 View 之间切换的方法(使用 pushViewController 和 popToRootViewController)。这些方法将从用于切换(导航)的 View 中调用。

但是引用资料说 UINavigationController 不是为子类化而设计的。 http://developer.apple.com/library/ios/#documentation/uikit/reference/UINavigationController_Class/Reference/Reference.html

你建议我做什么?

最佳答案

我将保留 UINavigationController,但不使用通常的 pushViewController:,而是像这样切换 View :

NSMutableArray *viewControllers = [self.navigationController.viewControllers mutableCopy];
// from here you can modify the order of controllers as much as you want
[viewControllers addObject:nextViewController];
[viewControllers removeObject:self];

[self.navigationController setViewControllers:viewControllers animated:YES];

如果您不想要动画的结果,您可以设置 animated:NO 并将 setViewControllers: 包含在 [UIView animate.. .] block ,或将您自己的自定义 CAAnimation 添加到导航 Controller 的层。

关于iphone - 子类化 UINavigationController 以在 View 之间进行自定义导航,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12929545/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com