需要访问tableView:heightForRowAtIndexPath中的单元格: [英] Need access to the cell in the tableView:heightForRowAtIndexPath:

查看:50
本文介绍了需要访问tableView:heightForRowAtIndexPath中的单元格:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要从 tableView:heightForRowAtIndexPath:访问表中的单元格由于我想使用数据,因此我将custome单元用于高度计算.我发现获取单元格的唯一方法是调用 tableView:cellForRowAtIndexPath:

I need to access my cell in the table from tableView:heightForRowAtIndexPath: since I want to use the data I have ion the custome cell for the height calculations. The only way I have found to get my cells is to call tableView:cellForRowAtIndexPath:

问题在于,调用 tableView:cellForRowAtIndexPath:实际上是在创建单元格,而不是对它们不执行任何操作.当需要将同一单元用于绘图时,将再次创建该单元.因此,对于相同的索引,该单元将创建两次.

The problem with that is that calling tableView:cellForRowAtIndexPath: is actually creating the cells and than doing nothing with them. when the same cell will need to be used for drawing purpose it will be created again. So for the same index the cell is created twice.

所以我想知道是否有更有效的方法来做到这一点.感谢您的帮助.

So I am wondering is there a more effective way to do it. Thanks for the help.

推荐答案

由于该方法尚不存在,因此您无权访问此方法中的单元格.在 tableView:cellForRowAtIndexPath:中创建单元格之前,将调用 tableView:heightForRowAtIndexPath:.

You don't have access to the cell in this method because it does not exist yet. tableView:heightForRowAtIndexPath: is called before you create the cell in tableView:cellForRowAtIndexPath:.

但这没关系,因为您不应该在单元格对象中保存模型信息.单元只是视图,您应始终保存在模型中构建单元所需的所有数据.

But it should not matter because you should not hold model information in the cell objects. The cells are only views and you should always hold the all the data you need to construct a cell in your model.

这篇关于需要访问tableView:heightForRowAtIndexPath中的单元格:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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