如何动态增加UITableViewCell的高度 [英] How can I increase the height of UITableViewCell dynamiclly

查看:80
本文介绍了如何动态增加UITableViewCell的高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个UITableView包括一个UITableViewCell的列表。我在方法(CGFloat)中设置UITableViewCells的高度tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath

I have an UITableView which includes a list of UITableViewCells. And I set the heights of UITableViewCells in method (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath.

但是,我需要增加 UITableViewCell 的高度。例如, UITableViewCell 的高度需要在选择单元格时增加100像素,有没有人知道如何做?

However, I need to increase the height of UITableViewCell when it is selected. For example, the height of UITableViewCell needs to increase 100 pixels when the cell is selected, does anyone know how to do it?

推荐答案


  1. 将所选索引存储在控制器中。

  2. 根据该索引返回单元格的高度:

  1. Store selected index in your controller.
  2. Return cell's height depending on that index:

CGFloat height = 30.0f;
...
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return indexPath.row == selectedIndex ? height+100 : height;
}


  • didSelectRowAtIndexPath 方法( beginUpdates endUpdates 之间的空块):

    - (void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
        index = indexPath.row;
        [tableView beginUpdates];
        [tableView endUpdates];      
    }
    


  • 这篇关于如何动态增加UITableViewCell的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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