查看层次结构、UITabBarController、在某些选项卡中添加更多视图

发布于 2024-12-07 16:51:51 字数 744 浏览 0 评论 0原文

所以我不确定做某事的最佳方法是什么,或者首选方法是什么。这基本上就是我们想要做的事情:

-UITabBarController 作为根
-第一个选项卡是 FruitViewController
-FruitViewController 可以推送 AppleViewController(不确定推送是否是正确的词,但基本上会转到下一个 viewController)
-AppleViewController 在 UIToolBar 中有一个后退按钮,可以返回 FruitViewController

-第二个选项卡是 VegetableViewController

-VegetableFruitViewController 可以推送 CeleryViewController

在两个 ViewController 的末尾,你可以推送另一个名为 CalorieViewController 的 ViewController。我的问题是,呈现每个选项卡视图控制器的最佳方式是什么?由于我希望两个选项卡都使用 CalorieViewController,为了重用它,我假设我需要保持它与其他 ViewController 不耦合。

我的同事实现的方式是,在每个选项卡上,创建该选项卡的所有 ViewController 并将其添加为子视图。根据按下的按钮,它会隐藏和显示其他视图。这似乎不是一个好主意。看起来presentModalViewController和dismissModalViewController(用于后退按钮)可能有效,但我不确定这是否是首选方法。

So I'm not sure what is the best way to do something, or the preferred way. Here's essentially what we are trying to do:

-UITabBarController as the root
-first tab is a FruitViewController
-FruitViewController can push an AppleViewController (not sure if push is the correct word, but basically go to the next viewController)
-AppleViewController has a back button in the UIToolBar to return to FruitViewController

-second tab is VegetableViewController

-VegetableFruitViewController can push CeleryViewController

At the end of both ViewControllers, you can push another ViewController called CalorieViewController. My question is that what's the best way to present view controllers per tab? Since I want both tabs to use CalorieViewController, in order to reuse it, I'm assuming I need to keep it non-coupled with the other ViewControllers.

The way my coworker implemented is, on each tab, all ViewControllers for that tab are created and added as a subview. Based on the button pressed, it hides and shows the other view. This seems like not a good idea. It seems like presentModalViewController, and dismissModalViewController (for the back button) might work, but I'm not sure if that's the preferred method.

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

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

发布评论

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

评论(1

流殇 2024-12-14 16:51:51

我建议您将每个选项卡的根视图控制器设置为 UINavigationController,并将当前为选项卡设置的视图控制器作为导航控制器的根视图控制器。这样您就可以随心所欲地推送和弹出视图。 UIViewController 甚至支持在将新的视图控制器推入堆栈时自动将选项卡栏推离屏幕。

I would suggest you make the root view controller for each tab a UINavigationController, with the view controller's that are currently set for the tabs as the root view controller of the navigation controller. That way you can push and pop views all you want. UIViewController even has support for automatically pushing the tab bar off the screen when pushing a new view controller onto the stack.

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