设置变量UITableViewCell的高度 [英] Setting variable UITableViewCell height

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

问题描述

我正在使用具有一些标签的自定义UITableViewCell.单元格中的字符串长度是可变的,因此在单元格中有一个标签,因此,我无法在heightForRowAtIndexPath方法中为单元格设置恒定的高度.我也不想将计算逻辑从我的自定义单元格中放到表委托中.

I am using a custom UITableViewCell, which has some labels. There is one label in the cell where the string length is variable, due to this i cannot set a constant height to the cell in heightForRowAtIndexPath method. Neither I want to place the calculation logic out of my custom cell into the table delegate.

推荐答案

如何在您的单元类上定义一个类方法来进行计算?您可能仍然必须将大量信息从委托传递给单元格类(例如模型对象或某些内容),并且可能必须复制单元格的 layoutSubviews drawRect:,但至少所有逻辑都将存在于单元格类中.

How about defining a class method on your cell class to do the calculations? You might still have to pass a bunch of information from the delegate to the cell class (like a model object, or some contents), and you might have to duplicate some code from your cell's layoutSubviews or drawRect:, but at least all of the logic would live within the cell class.

然后在您的委托中,可以分解出将索引路径转换为单元格类所需的任何逻辑,以自己的方法可以从 heightForRowAtIndexPath: cellForRowAtIndexPath:调用代码>.

Within your delegate, you can then factor out any logic you need to turn an index path into the cell class into its own method, callable from both heightForRowAtIndexPath: and cellForRowAtIndexPath:.

这篇关于设置变量UITableViewCell的高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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