[英]How to achieve an advanced table view header
I have a grouped UITableView
. 我有一个分组的
UITableView
。 Now unlike the default table view header my header should be next to the individual cells: 现在,与默认的表格视图标题不同,我的标题应该在各个单元格旁边 :
Standard: 标准:
[Header Cell]
[Item 1]
[Item 2]
What I need 我需要的
+-------+----------------+
| | Item 1a |
| h1 +----------------+
| | Item 1b |
+ - - - +----------------+
| Item 1c |
+------------------------+
| | Item 2a |
| h2 +----------------+
| | Item 2b |
+------------------------+
| | Item 3a |
| h3 +----------------+
| | -placeholder- |
+-------+----------------+
Some remarks: 一些说明:
The challenge here is the height of the header cell: 这里的挑战是标题单元格的高度:
clip subviews
then that header cell is shown but does not get pushed away at the correct position. clip subviews
则将显示该标题单元格,但不会在正确的位置被推开。 Update 1: I just realized that apple uses such a list for the search (grouped by messages, mails, contacts, calenders etc.). 更新1:我刚刚意识到苹果使用这样的列表进行搜索(按消息,邮件,联系人,日历等分组)。 So my question basically is how can I tweak
UITableView
in order to behave like the grouped search results... :-) 所以我的问题基本上是如何调整
UITableView
以便表现得像分组的搜索结果... :-)
(source: mshcdn.com ) (来源: mshcdn.com )
Update: I created a project on github, which does exactly this. 更新:我在github上创建了一个项目,它就是这样做的。 I have extracted all the relevant code for the behaviour into two classes (
BBFloatingHeaderViewController
& BBFloatingHeaderCell
). 我已经将行为的所有相关代码提取到两个类中(
BBFloatingHeaderViewController
和BBFloatingHeaderCell
)。 There is also an example project. 还有一个示例项目。 I hope this is useful for others :-)
我希望这对其他人有用:-)
Here's the project: besi/FloatingTableViewHeader 这是项目: besi / FloatingTableViewHeader
This is an excerpt from the readme: 这是自述文件的摘录:
Floating UITableView headers
浮动UITableView标头
These classes aim to copy the behaviour found in iOS built-in Spotlight search, where the search results are grouped by category and the icon of the respective category floats on the left side of the search results.
这些类旨在复制在iOS内置Spotlight搜索中发现的行为,该行为将搜索结果按类别分组,并且相应类别的图标浮在搜索结果的左侧。
Setup
设定
Check out the example project so see how to setup the classes.
查看示例项目,以便了解如何设置类。
- Add the
.m
+.h
files ofBBFloatingHeaderViewController
andBBFloatingHeaderCell
to your project.将
BBFloatingHeaderViewController
和BBFloatingHeaderCell
的.m
+.h
文件添加到您的项目中。- Create a TableView and set the Class of the ViewController to your subclass of
BBFloatingHeaderViewController
创建一个TableView并将ViewController的类设置为
BBFloatingHeaderViewController
的子类- Create the header cell in IB and set its class to your subclass of
BBFloatingHeaderCell
在IB中创建标头单元,并将其类设置为
BBFloatingHeaderCell
的子类- Make sure that your floating header view is the topmost view in the
BBFloatingHeaderCell
's view hierarchy.确保浮动标题视图是
BBFloatingHeaderCell
的视图层次结构中的最顶层视图。The result
结果
Floating Headers http://i.minus.com/jyea3I5qbUdoQ.png
浮动标头http://i.minus.com/jyea3I5qbUdoQ.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.