what would be a proper storyboard example of combining nav bars and tab bars in one app?

六月ゝ 毕业季﹏ 提交于 2019-12-29 07:49:08

问题


Hi I'm new to ios app dev. I've only done tutorials so far that have covered apps with either nav bars or tab bars. Now I want to make an app combining both.

So, say I have an app with a tab bar at the bottom with two tabs: friends and enemies. In each tab i plan to have a running list of who my friends and enemies are, so it will need an addPerson button on the nav bar of each tab.

given that scenario, what would be the proper way to organize my controllers and views and stuff? would both my tab controller and my nav controller be pointing to the same view controller?

i'm having trouble conceptualizing how my nav controller(2 nav controllers now?) would work in a more complex app.


回答1:


Here is how to set it up in your Storyboard. The TabBarController is the main controller. Each item of the TabBarController has its own NavigationController:

You probably want to use a TableViewController for your lists. Here I have shown the TableViewController as the rootViewController of the NavigationController.

A quick way to construct this is to delete everything in the Storyboard and then drag out two TableViewControllers placing one directly above the other. Select both by dragging an outline around them both, and then select Editor->Embed In->Tab Bar Controller from the menu. Then select each TableViewController in turn and select Editor->Embed In->Navigation Controller.




回答2:


If you want to set the title dynamically, use this function from your UITabBar delegate:

func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
    self.title = viewController.title
    print("Should select viewController: \(viewController.title) ?")
    return true;
}

Then just set the viewControllers title in the view controller like you would normally do with a UINavigationBar.



来源:https://stackoverflow.com/questions/26152643/what-would-be-a-proper-storyboard-example-of-combining-nav-bars-and-tab-bars-in

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!