在表视图顶部进行分段控制,但不在标题视图中 [英] Segmented control on top of a table view, not in the title view though

查看:140
本文介绍了在表视图顶部进行分段控制,但不在标题视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将分段控件放在tableview之上。我不希望它在导航控制器的标题视图上,我也不希望它与tableview一起滚动。有关我的意思的参考,请查看App Store应用程序,选择类别,然后选择任何类别。在那里你会看到我正在寻找的分段控件。带有付费,免费和发布日期段的人。我使用的代码不是IB,所以如果你知道如何用代码而不是IB拖放来回答这个问题。

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.

推荐答案

当您需要表视图控制器中除表视图之外的其他组件时,您不能使用 UITableViewController 。您需要使用 UIViewController 。您将 UITableView 添加为子视图,并使视图控制器成为表视图的数据源和委托。然后,您还可以将任何其他组件添加到视图控制器的视图中。这样,附加组件不会随表视图一起滚动。还有一些方法可以使视图控制器的行为与表视图控制器完全相同。这包括覆盖 setEditing:animated:方法来设置表视图的编辑属性。它包括取消选择 viewWillAppear:方法中任何当前选定的行。

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 表视图作为其视图。这可以防止您以不会滚动的方式将任何其他子视图添加到表视图控制器。

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.

这篇关于在表视图顶部进行分段控制,但不在标题视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆