如何在不重新加载UITableView或单个单元格的情况下增加单行高度[Swift]? [英] How to increase the single row height without reloading UITableView or individual cells [Swift]?

查看:178
本文介绍了如何在不重新加载UITableView或单个单元格的情况下增加单行高度[Swift]?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想展开行高并在里面显示内容。
我在视图中显示我的内容我希望当我点击一个单元格时它应该展开,如下图所示,但没有重新加载UITableview。

I want to expand the row height and show the content inside. I show my content in view I want when I tap on a cell it should expand like showed in the image below but without reloading the UITableview.


到目前为止我一直在尝试。

What I have tried till now.

1)我尝试扩展内部视图,但它没有工作

1) I tried expanding the view inside but it didn't work

2)我尝试添加rowAtIndex它变得复杂了

2) I tried adding rowAtIndex it was becoming complicated

3)我尝试更改更改行高度并滚动索引它工作正常但我不想那样。 (糟糕的是我必须重新加载表格视图)

3) I tried changing change row height and scroll at index it worked fine but I don't want like that. (bad thing I have to reload the table view)

但我得到了很多答案,但它没有解决我的问题,因为我在数组(数据源)中的数据是如果我在特定索引处刷新,则会不断更新索引中数组中的数据可能不同,可能会显示错误的输出。

But i got many answers but it didn't address my issue as my data in the array(data source) is continuously updated if I refresh at specific index the data in the array at the index might be different it might show the wrong output.

说明

我的意思是我有一个struct数组,一旦数据发生变化,我会继续在后台更新它并重新加载表视图,但是如果i在index处重新加载行,并且数组中的数据已经更改它可能显示重复正确吗?所以我想改变行的高度而不进行任何重新加载。

I mean I have an array of struct I keep on updating it in background once the data change and reload the table view but if the i reload the row at index and if the data in an array is already changed it might show duplication correct? so i want to just change the height of the row without doing any reload.

重新加载的问题是

虽然扩展数据可能会在阵列中发生变化。所以我已经创建了一个视图,所有信息都预先加载,一旦我点击单元格的高度应该从45变为76,一旦我从最后一个单元格76到45再次点击不同的单元格,这个单元格45到76。

while expanding the data might change in the array. so i already created a view and all the info is preloaded once i tap the height of the cell should change from 45 to 76 and once i tap different cell again from last cell 76 to 45 and this cell 45 to 76.

推荐答案

只能通过代表更改表高度没有其他方法可以做到这一点我会告诉你一个简单的方法。

Table height can only be changed through delegates there is no other way to do it i will show you a simple way to do it.

声明变量

var selectedIndex = NSIndexPath()

didSelectRowAtIndexPath 重新加载所选单元格

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

        selectedIndex = indexPath
        tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)

    }

内部 heightForRowAtIndexPath 返回尺寸

func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath == selectedIndex {

        return 100 //Size you want to increase to
    }
    return 50 // Default Size
}

这篇关于如何在不重新加载UITableView或单个单元格的情况下增加单行高度[Swift]?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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