Segmented control on top of a table view, not in the title view though

只谈情不闲聊 提交于 2019-12-09 06:54:55

问题


How can I put a segmented control on top of a tableview. I don't want it on the title view of the navigation controller and I don't want it to scroll with the tableview either. For reference of what I mean, please look at App Store app, choose Categories, then select any category. There you will see the segmented control I'm looking for. The one with 'Paid', 'Free', and 'Release Date' segments. I'm using the code not IB, so if you know how please answer this with code not IB drag and drop.


回答1:


When you need other components in a table view controller other than the table view, you can't use a UITableViewController. You need to use a UIViewController. You add the UITableView as a subview and you make the view controller the table view's data source and delegate. Then you can add any other components to the view controller's view as well. This way the additional components don't scroll with the table view. There's a little more plumbing to do to get the view controller to behave exactly like a table view controller. This includes overriding the setEditing:animated: method to set the editing property of the table view. It includes deselecting any currently selected row in the viewWillAppear: method.

UITableViewController has the table view as its view. This prevents you from adding any other subview to the table view controller in a way that they won't scroll.



来源:https://stackoverflow.com/questions/12993212/segmented-control-on-top-of-a-table-view-not-in-the-title-view-though

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