如何访问tableView中的cell.textLabel.text:heightForRowAtIndexPath:from tableView:cellForRowAtIndexPath:

时间:2010-10-11 02:13:30

标签: objective-c cocoa-touch uitableview

在tableView:heightForRowAtIndexPath:方法中,我需要获取tableView中的cell.textLabel.text的长度:cellForRowAtIndexPath。怎么办呢?

1 个答案:

答案 0 :(得分:1)

调用cellForRowAtIndexPath涉及调用heightForRowAtIndexPath,因此如果从heightForRowAtIndexPath调用它,则最终会进行无限递归。

您可以使用数据源检查用于填充cellForRowAtIndexPath中的单元格的相同数据,然后使用获取要插入到cell.textLabel.text中的文本的长度(或使用NSString UIKit additions计算标签的大小。