manually add UITabBar to UITableViewController

余生长醉 提交于 2019-12-21 21:56:13

问题


I have a standard app with a navigation controller managing several UITableViewController classes.

I want to add a UITabBar to the root view (a UITableViewController) to manage filtering the selection of objects showin in the UITableView.

I dont want/need a UITabBarController. The UITabBar is only for functionality and UI (radio-button style selection and familiar tabbar UI). I just want to manually create a UITabBar and add it to my view anchored/locked to the very bottom of the screen like is the case when using UITabBarControllers.

My main problem is I can't figure out what I should be adding the UITabBar as a subview too.

I dont want to add it to the controllers self.tableView because then it would be achored to the bottom of the scrolling TableView and not always visible on the bottom of the screen.

I also tried adding to the view.tableView.superview but that didnt seem to work as well.

Any help, or am I completely doing this "filtering of tableview data the wrong way" and should be using something else instead?


回答1:


So, the problem with a UITableViewController is it doesn't quite work as you might expect. It's very difficult to add 'locked' elements to a UITableView - the table footers and headers don't do the job, and as you've discovered adding it to the superview doesn't work.

The best solution in this case is actually to throw the table view controller out the window, and use a table view with a normal view controller.

What you want to do is create a normal UIViewController, and then add a table view to it. Your table view delegate and datasource can also be in this view controller.

You can then resize your table view to be smaller than the size of the screen, and add your UITabBar to the view controller's main view.



来源:https://stackoverflow.com/questions/5930526/manually-add-uitabbar-to-uitableviewcontroller

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