如何快速显示和隐藏表格视图单元格 [英] How to display and hide table view cells in swift

查看:78
本文介绍了如何快速显示和隐藏表格视图单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有两个不同自定义单元格的tableView.一个单元格只有很少的文本字段数据,其他单元格也有不同的文本字段数据,这里我需要折叠并隐藏每个单元格.我不知道该怎么办.请让我知道.

I have a tableView with two different custom cell. One cell have few textfields data and other also have different textfield data,here i need to collapse and hide the each cell. i don't know how to do this.Please let me know.

https://maniacdev.com/2013/03/an-open-source-ios-control-allowing-you-to-create-great-look-collapsible-lists-without-uitableview

请参考上面的链接,我希望尽快获得同样的提示.

Please refer the above link, i want the same in swift.

预先感谢

推荐答案

所以您要隐藏UITableViewCells之一?

So you want to hide one of your UITableViewCells?

我认为最简单的方法是向行数据数组"中添加更多信息.

Ill think the easiest way is to add some more information to your "Row Data Array".

例如:

您有10列,并且您想隐藏4个特定列".您有一个名为"getRowData"的函数-此函数将返回(当未选择过滤器时)所有10行.当您点击按钮时,您可以更改"getRowData"函数以仅返回所需的4行.

You have 10 Columns, and you want to hide 4 Specific Column. You have a function called "getRowData" - this returns (when no filter is selected) all 10 Rows. When you tap on a button, you could change your "getRowData" function to return only the 4 Rows you want.

在上面显示的示例中-您需要基于UITableViewController的一些可折叠列表.

With the example you showed above - you want some collapsible Lists, based on an UITableViewController.

因此,您有3个主要类别(在此示例中)-如果用户单击一个标题",则要展开该类别的列表.

So you have (In this example) 3 Main Categories - and if the User click on one "Title" you want to expand the list for this Category.

因此您可以使用Sections-为每个类别创建一个Section.然后执行以下操作:

So you could use Sections - create a Section for each Category. Then implement something like this:

//为激活的类别"创建一个主变量

// create a main variable for your "activated Category"

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"-因此是第一个,请展开此部分.因此,请执行以下操作:

Check here which section was clicked by the user. If (for example "0" - so the first one, expand this section. So do something like this:

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    if(indexPath.section == enabledCategory) {
        return rows // return rows you want to show
    }

您还需要在此处更改行数:

You need also to change the count of rows in here:

override func numberOfSectionsInTableView(tableView: UITableView) -> Int {

    return 3
}

在您的示例中,该值应始终为3.

this should be (in your example) always 3.

override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {

这取决于您的部分//类别

This depends on your section // Category

这篇关于如何快速显示和隐藏表格视图单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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