开发者

View Hierarchy, UITabBarController, adding more views in certain tabs

开发者 https://www.devze.com 2023-04-10 02:41 出处:网络
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:

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, 开发者_Go百科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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号