所以你想隐藏你的 UITableViewCell 之一?
我认为最简单的方法是在“行数据数组”中添加更多信息。
例如:
您有 10 个列,并且您想隐藏 4 个特定列。您有一个名为“getRowData”的函数 - 这将返回(当未选择过滤器时)所有 10 行。当您点击一个按钮时,您可以更改您的“getRowData”函数以仅返回您想要的 4 行。
对于上面显示的示例 - 您需要一些基于 UITableViewController 的可折叠列表。
所以你有(在这个例子中)3个主要类别——如果用户点击一个“标题”你想展开这个类别的列表。
因此您可以使用部分 - 为每个类别创建一个部分。然后实现这样的东西:
// 为“激活的类别”创建一个主变量
var enabledCategory:Int = 0 // you could add i base value
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let indexPath = tableView.indexPathForSelectedRow();
enabledCategory = indexPath.row;
....
在此处检查用户单击了哪个部分。如果(例如“0” - 所以第一个,展开这个部分。所以做这样的事情:
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if(indexPath.section == enabledCategory) {
return rows // return rows you want to show
}
您还需要在此处更改行数:
override func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 3
}
这应该(在您的示例中)始终为 3。
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
这取决于您的部分 // 类别