iphone - 如何实现高级表格 View 标题
<p><p>我有一个分组的 <code>UITableView</code>。现在与默认的表格 View 标题不同,我的标题应该是 <em>next</em> 到各个单元格:</p>
<p>标准:</p>
<pre><code>
</code></pre>
<p>我需要什么</p>
<pre><code>+-------+----------------+
| |Item 1a |
|h1 +----------------+
| |Item 1b |
+ - - - +----------------+
| Item 1c |
+------------------------+
| |Item 2a |
|h2 +----------------+
| |Item 2b |
+------------------------+
| |Item 3a |
|h3 +----------------+
| |-placeholder- |
+-------+----------------+
</code></pre>
<p>一些备注:</p>
<ul>
<li>H1 组包含三个项目</li>
<li>H2 组有两个项目</li>
<li>H3 组只有一个项目(我必须插入一个占位符单元格,以便标题单元格可以具有两个项目单元格的完整高度</li>
<li>当用户滚动列表时,应将标题向上推,使两个标题单元格不重叠。</li>
</ul>
<p>这里的挑战是标题单元格的高度:</p>
<ul>
<li>如果我将高度设置为 0 并取消选中 <code>clip subviews</code>,则会显示该标题单元格,但不会在正确的位置被推开。</li>
<li>如果我将标题单元格的高度设置为视觉高度,那么在表格的整个宽度<em>中会有一个空白空间,我不想要...</em></li>
</ul>
<p><strong>更新 1:</strong> 我刚刚意识到苹果使用这样的列表进行搜索(按消息、邮件、联系人、日历等分组)。所以我的问题基本上是如何调整 <code>UITableView</code> 以使其表现得像分组搜索结果... :-)</p>
<p> <a href="/image/fFz1E.jpg" rel="noreferrer noopener nofollow"><img src="/image/fFz1E.jpg" alt=""/></a> <br/>
<sub>(来源:<a href="http://6.mshcdn.com/wp-content/uploads/2010/08/2photo.jpg" rel="noreferrer noopener nofollow">mshcdn.com</a>)</sub> </p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p><strong>更新:</strong>我在 github 上创建了一个项目,正是这样做的。我已将行为的所有相关代码提取到两个类( <a href="https://github.com/besi/FloatingTableViewHeader/blob/master/BBFloatingHeaderTableViewController.h" rel="noreferrer noopener nofollow"><code>BBFloatingHeaderViewController</code></a> 和 <a href="https://github.com/besi/FloatingTableViewHeader/blob/master/BBFloatingHeaderCell.h" rel="noreferrer noopener nofollow"><code>BBFloatingHeaderCell</code></a> )。还有一个示例项目。我希望这对其他人有用:-)</p>
<p>这是项目:<a href="https://github.com/besi/FloatingTableViewHeader" rel="noreferrer noopener nofollow">besi/FloatingTableViewHeader</a> </p>
<p>这是自述文件的摘录:</p>
<blockquote>
<h1>Floating UITableView headers</h1>
<p>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.</p>
<h2>Setup</h2>
<p>Check out the example project so see how to setup the classes.</p>
<ol>
<li>Add the <code>.m</code> + <code>.h</code> files of <code>BBFloatingHeaderViewController</code> and <code>BBFloatingHeaderCell</code> to your project.</li>
<li>Create a TableView and set the Class of the ViewController to your subclass of <code>BBFloatingHeaderViewController</code></li>
<li>Create the header cell in IB and set its class to your subclass of <code>BBFloatingHeaderCell</code></li>
<li>Make sure that your floating header view is the topmost view in the <code>BBFloatingHeaderCell</code>'s view hierarchy.</li>
</ol>
<h2>The result</h2>
<p><a href="http://i.minus.com/jyea3I5qbUdoQ.png" rel="noreferrer noopener nofollow">Floating Headers http://i.minus.com/jyea3I5qbUdoQ.png</a></p>
</blockquote></p>
<p style="font-size: 20px;">关于iphone - 如何实现高级表格 View 标题,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/11475897/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/11475897/
</a>
</p>
页:
[1]