如何动态增加UITableViewCell的高度

编程入门 行业动态 更新时间:2024-10-25 02:28:26
本文介绍了如何动态增加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?

推荐答案

  • 将所选索引存储在控制器中。
  • 根据该索引返回单元格的高度:

  • Store selected index in your controller.
  • 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的高度

    本文发布于:2023-11-23 03:22:18,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1619896.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:高度   动态   UITableViewCell

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!