ios – 如何更改UITableViewCell的高度?

ios – 如何更改UITableViewCell的高度?,第1张

概述我试图让UITableViewCell在点击特定单元格时显示有关特定单元格的更多内容.一旦细胞膨胀并再次敲击,细胞应缩小回原始大小. 我很确定必须使用委托heightForRowAtIndexPath和didSelectRowAtIndexPath完成某些 *** 作,但我不知道如何使用didSelectRowAtIndexPath选择特定的表格单元格行. // Height of table cell 我试图让UItableVIEwCell在点击特定单元格时显示有关特定单元格的更多内容.一旦细胞膨胀并再次敲击,细胞应缩小回原始大小.

我很确定必须使用委托heightForRowAtIndexPath和dIDSelectRowAtIndexPath完成某些 *** 作,但我不知道如何使用dIDSelectRowAtIndexPath选择特定的表格单元格行.

// Height of table cell rowsfunc tableVIEw(tableVIEw: UItableVIEw,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGfloat {    return 45}//On cell tap,expandfunc tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) {    self.tableVIEw.rowHeight = 75;}

此外,是否可以隐藏从父单元溢出的任何内容?有点像溢出:隐藏;在CSS中.

解决方法 在dIDSelectRowAtIndexPath中选择的tablevIEw上声明一个全局变量NSInteger类型和存储行,并在此处重新加载.在heightForRowAtIndexPath中检查行并在那里增加高度.
试试这样

var selectedindex : NSInteger! = -1 //Delecre this global  func tableVIEw(tableVIEw: UItableVIEw,dIDSelectRowAtIndexPath indexPath: NSIndexPath) {    if indexPath.row == selectedindex{        selectedindex = -1    }else{        selectedindex = indexPath.row    }    tableVIEw.reloadData()}func tableVIEw(tableVIEw: UItableVIEw,heightForRowAtIndexPath indexPath: NSIndexPath) -> CGfloat {    if indexPath.row == selectedindex    {        return 75    }else{        return 45    }}
总结

以上是内存溢出为你收集整理的ios – 如何更改UITableViewCell的高度?全部内容,希望文章能够帮你解决ios – 如何更改UITableViewCell的高度?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1005084.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-22
下一篇2022-05-22

发表评论

登录后才能评论

评论列表(0条)

    保存