在故事板中创建标题时,将UITableView标题视图粘贴到顶部 [英] Stick UITableView header view to top when creating header in storyboard

查看:101
本文介绍了在故事板中创建标题时,将UITableView标题视图粘贴到顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这里的答案创建了一个表格视图标题。

I have created a table view header using the answer here.

我的问题是,当以这种方式创建标题时,它在向下滚动时不会粘住到我的UITableView的顶部。如果我在viewForHeader内部的代码中创建我的标题,那么它确实会坚持下去。

My problem is that when creating the header this way, it does not "stick" to the top of my UITableView when scrolling down. If I create my header in code inside of viewForHeader then it does stick.

如果我在故事板中创建它,如何让我的标题在滚动时保持在顶部?其他2个问题此处此处问这个问题,但从来没有得到答案。

How can I get my header to stick to the top while scrolling if I create it in storyboard? 2 other askers here and here asked this question and never got an answer.

是的,我的UITableView已经是简单的风格,没有分组。

And yes my UITableView is already plain style, not grouped.

推荐答案

rdelmar的评论帮助我理解了它无法正常工作的原因。以下是我在实践中为解决问题所做的工作:

rdelmar's comment helped me understand the reasoning behind it not working. Here is what I did in practice to fix the problem:

我必须将故事板中的标题视图拖到第一个响应者的位置。你会发现你实际上无法将标题视图向下拖动到视图本身上,你必须将元素从文档大纲中向下拖动。

I had to drag the header view in storyboard down by where the first responder is. You'll notice you can't actually drag the header view down on the view itself, you'll have to drag the element down from the document outline.

我也是必须实现viewForHeaderInSection(返回我做出口的标题视图)和heightForHeaderInSection。

I also had to implement viewForHeaderInSection (returning the header view that I made an outlet) and heightForHeaderInSection.

每次你想通过情节提要编辑视图时,你都要拖动它备份以进行编辑,然后将其向下拖动以使其正常工作。

Every time you want to edit the view via storyboard, you'll have to drag it back up to edit it, then drag it back down so it works correctly.

这篇关于在故事板中创建标题时,将UITableView标题视图粘贴到顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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