iOS 8 Self Sizing Cells - 允许零高度 [英] iOS 8 Self Sizing Cells - Allow Zero Height

查看:112
本文介绍了iOS 8 Self Sizing Cells - 允许零高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用自我调整单元格功能,它可以很好地工作,直到我想完全隐藏单元格。为此我离开了heightForRowAtIndexPath并设置了以下内容:

I am using the self sizing cell feature and it works well until I want to hide a cell completely. I moved away from heightForRowAtIndexPath for this and I setup the following:

override func viewDidLoad() {
    self.tableView.rowHeight = UITableViewAutomaticDimension
    self.tableView.estimatedRowHeight = 0
}

但是当我没有tableviewcell的文本呈现时,我收到以下消息:

However when I have no text for a tableviewcell to render I get the following message:


仅警告一次:检测到约束模糊的情况$ b对于tableview单元格的内容视图,$ b建议高度为零。考虑到无意识的崩溃,使用标准高度
,我们是

Warning once only: Detected a case where constraints ambiguously suggest a height of zero for a tableview cell's content view. We're considering the collapse unintentional and using standard height instead.

我真的只需要一种方式隐藏/动态显示内容。我正在使用静态tableview,所以也许我接近这个错误?

I really just need a way to hide / show content dynamically. I am using a static tableview for this, so maybe I am approaching this wrong?

推荐答案

我找到了解决方案。

首先,要使静态表正确使用自定义大小,每个表格单元格只能有一个标签。我试图将大量内容放入一个单元格中,只有第一个标签会对单元格进行调整。我可能错误的是每个单元格一个标签的规则,问题可能是约束/自动布局相关。我已经看过这个WWDC视频了,我设置它的方式应该是我现有的约束,因为它们设置为单元格的contentView。

First, for a static table to use self sizing correctly, you can only have one label per table cell. I was trying to put in a lot of content into a cell and only the first label would size the cell. I could be wrong about the rule of one label per cell, and the problem might be constraints / auto layout related. I've watched the WWDC video on this, and the way I had it setup, should have worked with my existing constraints, as they where set to the contentView of the cell.

其次,UI更新需要与开始和结束规则以及重新加载相结合。

Secondly, the UI updates needed to be coupled with begin and end rules, and a reload.

tableView.beginUpdates()
//-- You Table UI changes
tableView.reloadData()
tableView.endUpdates()

您还可以将reloadData替换为reloadRowsAtIndexPaths以特定于要更新的​​行,但我的实例需要更新所有行。

You can also replace reloadData with reloadRowsAtIndexPaths to be specific to the rows to update, but my instance required all rows to be updated.

这篇关于iOS 8 Self Sizing Cells - 允许零高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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