使用多个视图计算自定义单元格高度 [英] Calculate custom cell height with multiple views iphone

查看:45
本文介绍了使用多个视图计算自定义单元格高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用多个子视图(例如标签,imageViews,按钮等)来计算我的自定义单元格高度.

I want to calculate my custom cell height with multiple subviews like labels, imageViews, buttons etc.

如何计算此单元格大小?

How do I calculate this cell size?

似乎不建议在cellForRowAtIndxPath中执行此操作,并且在heightForRowAtIndexPath中也使用Cell的实例,它会无限循环.

It seems it's not recommended to do it in cellForRowAtIndxPath, also taking an instance of Cell in heightForRowAtIndexPath, it goes in infinite loop.

我能够在自定义单元格类中计算单元格的高度,但是我不确定应该在哪里返回它.

I'm able to calculate the height for cell in the custom cell class but I'm not sure wheather where should I return it.

由于该方法heightForRowAtIndexPath没有得到一个单元格实例,如何告诉此方法我要为其渲染所计算高度的单元格类型?

Since the method, heightForRowAtIndexPath doesn't get a cell instance, how to tell this method the type of cell for which I want to render the calculated height?

感谢您的帮助.

先感谢

推荐答案

理想地,您应该能够计算单元格的高度而不必为其创建单元格. tableView:heightForRowAtIndexPath:将为表中的每个单元格(不仅仅是屏幕上的单元格)调用,如果您必须使用该方法创建完整的单元格对象,则可能会对性能产生重大影响

Ideally, you should be able to calculate the height of the cell without having to create a cell for it. tableView:heightForRowAtIndexPath: will be called for every cell in your table (not just the ones on screen) and if you have to create a complete cell object in that method it will probably have a big impact on performance.

您必须基于 indexPath 参数派生单元格的类型,就像在 tableView:cellForRowAtIndexPath:

You have to derive the type of cell based on the indexPath argument, in the same way you do it in tableView:cellForRowAtIndexPath:

这篇关于使用多个视图计算自定义单元格高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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