如何使用 Storyboard 实现自定义表格视图节页眉和页脚 [英] How to Implement Custom Table View Section Headers and Footers with Storyboard

查看:35
本文介绍了如何使用 Storyboard 实现自定义表格视图节页眉和页脚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

不使用故事板,我们可以简单地将 UIView 拖到画布上,进行布局,然后将其设置在 tableView:viewForHeaderInSectiontableView:viewForFooterInSection 委托方法.

Without using a storyboard we could simply drag a UIView onto the canvas, lay it out and then set it in the tableView:viewForHeaderInSection or tableView:viewForFooterInSection delegate methods.

我们如何使用 StoryBoard 实现这一点,而我们无法将 UIView 拖到画布上

推荐答案

我知道这个问题是针对 iOS 5 的,但为了未来读者的利益,请注意有效的 iOS 6 我们现在可以使用 dequeueReusableHeaderFooterViewWithIdentifier 而不是 dequeueReusableCellWithIdentifier.

I know this question was for iOS 5, but for the benefit of future readers, note that effective iOS 6 we can now use dequeueReusableHeaderFooterViewWithIdentifier instead of dequeueReusableCellWithIdentifier.

因此在viewDidLoad 中,调用registerNib:forHeaderFooterViewReuseIdentifier:registerClass:forHeaderFooterViewReuseIdentifier:.然后在 viewForHeaderInSection 中,调用 tableView:dequeueReusableHeaderFooterViewWithIdentifier:.您不使用带有此 API 的单元格原型(它是基于 NIB 的视图或以编程方式创建的视图),但这是用于出列页眉和页脚的新 API.

So in viewDidLoad, call either registerNib:forHeaderFooterViewReuseIdentifier: or registerClass:forHeaderFooterViewReuseIdentifier:. Then in viewForHeaderInSection, call tableView:dequeueReusableHeaderFooterViewWithIdentifier:. You do not use a cell prototype with this API (it's either a NIB-based view or a programmatically created view), but this is the new API for dequeued headers and footers.

这篇关于如何使用 Storyboard 实现自定义表格视图节页眉和页脚的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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