隐藏UITableview单元格 [英] Hide UITableview cell

查看:100
本文介绍了隐藏UITableview单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从UITableView隐藏单元格.就像删除动作一样,但我只想将其隐藏起来,以便以后在相同位置显示它.

i'm trying to Hide a cell from a UITableView. just like the delete action do but i just want to hide it to later show it in the same position.

我知道UITableViewCell具有一个名为隐藏"的属性,但是当我使用此属性隐藏Cell时,它会隐藏但没有动画,并且它们会留出空白

i know that UITableViewCell has a property called "Hidden" but when i hide the Cell using this property it hide but no animated and they leave a blank space

示例:

  1. 第一个单元格
  2. 第二个单元格
  3. 第三格

当我隐藏第二个单元格时,第三个单元格的位置可能会更改为2?

it's possible that when i hide the second cell, that third cell change position to 2 ?

谢谢

推荐答案

一种有效地隐藏"带有动画的行而不实际删除它的方法是将其高度设置为零.您可以通过覆盖-tableView:heightForRowAtIndexPath:来实现.

One way to effectively "hide" a row with animation and without actually removing it is to set it's height to zero. You'd do so by overriding -tableView:heightForRowAtIndexPath:.

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    CGFloat height = 0.0;
    if (isRowHidden) {
        height = 0.0;
    } else {
        height = 44.0;
    }
    return height;
}

(当然,您不希望无条件地只想为要隐藏的特定行返回0.0.)

(You'd only want to return 0.0 for the specific row or rows you want to hide of course, not unconditionally).

仅更改此方法的返回值并不会使表视图自动调整行的高度,要做到这一点,您可以进行以下调用.

Simply changing the return value of this method doesn't make the table view automatically adjust the row's height, to make it do so you make the following calls.

isRowHidden = YES;
[tableView beginUpdates];
[tableView endUpdates];

如果这样做,您将看到两者之间的动画外观/消失过渡.

If you do so you'll see an animated appearance/disappearance transition between the two.

这篇关于隐藏UITableview单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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