如何使用iOS自动调整大小单元格,而不指定估计行高? [英] How do I use iOS auto resizing cells without specifying estimated row height?

查看:206
本文介绍了如何使用iOS自动调整大小单元格,而不指定估计行高?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想利用自动布局在iOS 8中自动照顾我的单元格高度,但我讨厌如何精细估计行高度使滚动(跳跃,滚动位置不可预测等)。

I want to leverage Auto Layout taking care of my cell heights automatically in iOS 8, but I hate how finicky estimated row heights make scrolling (jumpy, scroll position unpredictable, etc.).

有没有办法不使用估计,以便表视图预先计算所有的行高度,就像它在iOS 7之前(不是太多的单元格,所以不是性能问题),但使用iOS 8的自动计算高度? / p>

Is there a way to not use estimation so that the table view precalculates all row heights like it did pre iOS 7 (not too many cells so not a performance issue) but uses iOS 8's auto calculating for heights?

推荐答案

编辑:

没有办法使用动态大小使用此属性。 estimatedRowHeight 告诉系统使用动态大小,假设您在单元格中使用Auto布局。

There is no way to use dynamic sizing without using this property. estimatedRowHeight tells the system to use a dynamic size, assuming you used Auto layout in you cell.

观看WWDC 2014视频226。

Watch WWDC 2014 Video 226.

//

非常简单 - 在故事板中创建原型单元格, superview top / bottom(也称为单元格内容视图),这意味着您的子视图具有顶部/底部约束,在必要时可以推动单元格大小。

Very simple - create your prototype cell in the Storyboard, add constraints to the superview top/bottom (aka the cell content view), meaning your subviews have top/bottom constraints that will "push" the cell size when necessary.

TableView和单元格高度设置为默认值。如果这是问题(自动布局需要更多的高度比默认44点),那么请务必在代码:
tableView.rowHeight = UITableViewAutomaticDimension
不要忘记设置 estimatedRowHeight 来告诉系统您要启用动态大小调整。

Make the that both the TableView and the Cell height are set to Default. If that's problem (auto layout required more height than the default 44 pts) then make sure to do it in code: tableView.rowHeight = UITableViewAutomaticDimension Don't forget to set the estimatedRowHeight to tell the system you want dynamic sizing enabled.

这篇关于如何使用iOS自动调整大小单元格,而不指定估计行高?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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