集合视图标题未显示 [英] Collection View Header not showing up

查看:98
本文介绍了集合视图标题未显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向 UICollectionView 添加标头。我使用了故事板并检查了Section Header。出现了一个新单元格,我正在尝试向其中添加内容(带有一些文本的标签)。问题是我可以在故事板中看到标签,但它不会出现在运行时。

I am trying to add a header to UICollectionView. I used storyboard and checked Section Header. A new cell appeared and I am trying to add content to it (A label with some text). The issue is I can see the label in the storyboard but it does not appear in runtime.

为了确保显示标题,我将背景颜色更改为黄色,并且我能够在运行时看到黄色标题。仍然没有标签。

In order to make sure that header is showing up, I changed the background color to yellow and I was able to see yellow header in runtime. Still no label.

非常感谢帮助。

推荐答案

找到修复。我在 viewDidLoad 中调用 registerClass:forSupplementaryViewOfKind:withReuseIdentifier:

Found the fix. I was calling registerClass:forSupplementaryViewOfKind:withReuseIdentifier: in viewDidLoad.

使用故事板时,注册是在内部完成的,上面的调用搞砸了。删除代码行修复了问题。

When using storyboards, registration is done internally and the above call was messing things up. Deleting the line of code fixed the problem.

这篇关于集合视图标题未显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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