Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView: the proper way to display a separator for the last cell

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.

enter image description here 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. 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.

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

In iOS 7 and later, cell separators do not extend all the way to the edge of the table view. This property sets the default inset for all cells in the table, much like rowHeight sets the default height for cells. It is also used for managing the “extra” separators drawn at the bottom of plain style tables.

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.

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.

like image 255
dariaa Avatar asked Nov 04 '13 12:11

dariaa


1 Answers

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

self.tableView.tableFooterView = [[UIView alloc] init]; 
like image 65
Timo Cengiz Avatar answered Sep 28 '22 01:09

Timo Cengiz