UITableView:显示最后一个单元格的分隔符的正确方法 [英] UITableView: the proper way to display a separator for the last cell

查看:101
本文介绍了UITableView:显示最后一个单元格的分隔符的正确方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题是在表/节的最后一个单元格中显示分隔符的最正确方法是什么。

The question is what's the right-most way to display a separator in the last cell in a table/section.

基本上这就是我所追求的。

Basically this is what I am after.


这是来自原生音乐应用程序,这让我觉得应该可以通过 UITableView ,他们不会使用某些私有API进行单元格分隔符,对吗?

This is from the native music app, which makes me think that it should be possible to achieve just by means of UITableView, they would not be using some private API for cell separators, right?

我知道你可以在不使用实际分隔符的情况下逃脱但在单元格底部添加一条像素线。但我不是这种方法的粉丝,因为

I know you can get away without using actual separators, but adding one pixel line in the bottom of the cell. But I'm not a fan of this approach because


  1. 选择/突出显示单元格分隔符 上一个单元格的分隔符会自动隐藏(请参阅选中你必须疯狂的第二个屏幕截图)。这是
    我希望UITableView处理的东西,而不是自己如果我使用一个像素行
    (当细胞分离器没有扩展所有
    到达边缘时,这是特别方便的表视图,分隔符和选定的单元格背景看起来不太好。)

  2. 我希望我的单元格尽可能保持平坦以进行滚动性能。

  1. When a cell is selected/highlighted its separator and the separator of the previous cell are automatically hidden (see the second screenshot with "You've got to be crazy" selected). And this is something I want UITableView to handle instead of doing myself if I use one-pixel line (which is especially handy when cell separators do not extend all the way to the edge of the table view, separators and selected cell background do not look nice together).
  2. I would like to keep my cells as flat as possible for scrolling performance.

UITableView参考中还有一些东西让我觉得有一种简单的方法可以得到我想要的东西:

Also there is something in UITableView reference that makes me think that there is an easy way to get what I want:


在iOS 7及更高版本中,单元格分隔符不会一直扩展到表格视图的
边缘。此属性设置表中所有
单元格的默认插入,就像rowHeight设置
单元格的默认高度一样。 它还用于管理在普通样式表底部以
绘制的额外分隔符。

有人知道如何使用普通样式表底部绘制的这些额外分隔符吗?因为这正是我所需要的。
我想将 separatorInset 分配给 UITableView ,而不是 UITableViewCell 可以做到这一点,但事实并非如此,最后一个单元格仍然缺少它的分隔符。

Does somebody know how exactly to use these "extra" separators drawn at the bottom of plain style tables? Because this is exactly what I need. I thought assigning separatorInsetto the UITableView, not UITableViewCell would do the trick, but it does not, the last cell is still missing its separator.

现在我只看到一个选项:有一个自定义部分页脚模仿最后一个单元格的分隔符。这并不好,特别是如果你想使用 tableView:titleForFooterInSection:方法获得一个实际的页脚。

Right now I only see one option: to have a custom section footer to mimic the separator for the last cell. And this is not good, especially if you want to have an actual section footer using tableView:titleForFooterInSection: method.

推荐答案

这对我来说是完美无缺的,可以在最后一个单元格中添加一个分隔符。玩得开心!

This worked flawlessly for me to add a separator to the last cell. have fun!

self.tableView.tableFooterView = [[UIView alloc] init];

这篇关于UITableView:显示最后一个单元格的分隔符的正确方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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