UITableView标头在运行时的动态高度 [英] UITableView header dynamic height in run-time

查看:62
本文介绍了UITableView标头在运行时的动态高度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道有很多关于它的文章,但是也许在最新的iOS中对此有一些更新...

I know there are a lot of posts about it, but maybe in newest iOS there are some updates on this...

我认为我们每个人都有一个创建viewController的任务,该任务顶部包含很多内容,大多数内容都是自动调整大小的,并且在最底部它表明您需要显示一些有很多项目...

I think all of us had a task to create viewController that has a lot of content at the top, most of them are self-sizing, and at the very bottom it figures out that you need to show some tableView with many items...

可以使用的 first 解决方案是使用UIScrollView,而根本不关心reusableCells.
second 是每次需要时使用UITableViewheaderView并手动调整其高度(或通过调用systemLayoutSizeFittingSize:).
也许第三种解决方案是分别使用UITableView和自定义大小的UIView,并且在tableView上具有UIEdgeInsets.并且取决于哪个对象具有更高的"zIndex",它可能会在处理交互方面带来问题...
第四解决方案是使用单元格上方的全部内容,就像单独的单元格一样.完全不确定这是个好主意...

The first solution that can be done is to use UIScrollView, and don't care about reusableCells at all.
The second is to use UITableView's headerView and adjust its height manually (or by calling systemLayoutSizeFittingSize:) each time when it is needed.
Maybe the third solution is to use UITableView and self-sized UIView separately, with having UIEdgeInsets on tableView. And depending on what object has higher "zIndex", it can bring problems with handling interactions...
The forth solution is to use whole content above the cell, like a separate cell. Not sure this is a good idea at all...

问题:此问题是否有新解决方案?我已经有2年没有深入研究了……也许在新的iOS中,像UIScrollView的reusableViews之类的东西……当然,目标是拥有可重复使用的单元格和使用自动布局的标头,而无需更新手动将其高度...

Question: Is there any new solution to this problem? I haven't dig into it for like 2 years... Maybe in new iOS there is something like reusableViews for UIScrollView... Of course, the goal is to have reusable cells, and header with using autolayout without necessity of updating its height manually...

推荐答案

这就是我的处理方式

使用tableview 我已经在XIB中为标题创建了UI

Using tableview I have created the UI For the header in XIB

现在使用以下委托方法

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {

}

我为标题创建一个UIView并根据内容计算高度并将其返回.

I Create a UIView for the header and calculate the height based on the content and return the same.

现在我可以从以下委托方法返回相同的标题视图

Now i can return the same header view from the following delegate method

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

}

根据本节,我再次从xib创建视图,然后从方法中返回该视图.

Based on the section i again create a view from xib and return that view from the method.

在我的情况下,我只需要一个表标题视图,因此我保留了2个部分并返回了第一部分的标题视图.

In my case i needed only one headerview for table so i kept 2 sections and returned the headerview for section one.

这篇关于UITableView标头在运行时的动态高度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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