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

查看:11
本文介绍了在故事板中创建标题时将 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天全站免登陆