Using UITabBar without creating a project with UITabBarController

两盒软妹~` 提交于 2019-12-25 02:13:57

问题


I want to use a UITabBar in my project. I did not create a project that is uitabbar based. I was wondering how for only one page I would be able to use a UITabBar. I can add it to the page, but I would like to add it and use it on a file and not throughout the whole project. I would also like to not restart this project since I have a navigation based project template being used and would like to just add the UITabBar to a single page to go back and forth with two views.

The flow of my project is Splash screen -> Login Page -> TableView -> TableView with search bar. What I want to do at the tableView with the search bar is to have a UITabBar at the bottom that will allow me to go between the one tableView to a calendar page and keep the search bar at the top. I could use a toolbar but I think the tabbar looks better.

Any help would be much appreciated.


回答1:


First of all, just so you know, you'll be violating the HIG:

A tab bar appears at the bottom edge of the screen and should be accessible from every location in the application.

Users expect tab bars to be used for the highest-level navigation in their app, so using it in other situations is confusing, and I'd recommend that you go with a different UI paradigm.

Having said that, if your heart is set on doing this, it's easy to programatically create a tab bar controller:

UITabBarController *tabBarController = [[UITabBarController alloc] init];
[tabBarController setViewControllers:[NSArray arraywithObjects: firstViewController, secondViewController, nil] 
                            animated:NO];

And to set the tab bar items:

firstViewController.tabBarItem = [UITabBarItem initWithTabBarSystemItem:UITabBarSystemItemFavorites tag:0];
secondViewController.tabBarItem = [UITabBarItem initWithTabBarSystemItem:UITabBarSystemItemFeatured tag:1];

Then just do whatever you need to do with tabBarController: present it modally (shudder), push it onto a navigation controller (oh god, the humanity), or whatever.



来源:https://stackoverflow.com/questions/9470526/using-uitabbar-without-creating-a-project-with-uitabbarcontroller

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