如何从tableView:cellForRowAtIndexPath中访问tableView:heightForRowAtIndexPath:中的cell.textLabel.text: [英] How to access cell.textLabel.text in tableView:heightForRowAtIndexPath: from tableView:cellForRowAtIndexPath:

查看:55
本文介绍了如何从tableView:cellForRowAtIndexPath中访问tableView:heightForRowAtIndexPath:中的cell.textLabel.text:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In the tableView:heightForRowAtIndexPath: method I need to get the length of cell.textLabel.text in tableView:cellForRowAtIndexPath. How can this be done?

推荐答案

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

Calling cellForRowAtIndexPath involves calling heightForRowAtIndexPath, so if you call it from heightForRowAtIndexPath, you end up in an infinite recursion.

您可以做的是使用数据源检查用于填充cellForRowAtIndexPath中单元格的相同数据,然后使用get来获取文本的长度重新插入cell.textLabel.text中(或使用添加了NSString UIKit (计算出标签的大小)。

What you can do is use your data source to examine the same data you would use to populate the cell in cellForRowAtIndexPath, and then use get the length of the text you're going to insert into cell.textLabel.text (or use NSString UIKit additions to compute what the size of your label will be).

这篇关于如何从tableView:cellForRowAtIndexPath中访问tableView:heightForRowAtIndexPath:中的cell.textLabel.text:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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