Wednesday, August 8, 2012

Hide UITableView Empty Cell Separator Lines


Hide UITableView Empty Cell Separator Lines

Plain UITableView displays cell separator lines, when table is empty or has only a few real cells. This is the default behaviour - and it is good. You should not change it.

But sometimes it looks a bit too weird. When your cells have different heights, all empty cells following the last real one will use last cell's height. If this changes at every table refresh, the "jumping" empty cells start annoying users. Or at least developers.

Easy way is to define that table has no cell separator lines:
self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
Hard way, if you need separator lines, is to define that table has no separator lines and create cell separator lines as part of custom UITableViewCell. Bottom part of cell, obviously, and most likely using really thin graphics image. Remember to define image autosizing and mode properly.

Another way is to define an empty UITableView's tableFooterView:
UIView *footer =
    [[UIView alloc] initWithFrame:CGRectZero];
self.myTable.tableFooterView = footer;
[footer release];
You really should not mess with default settings. Users have seen it before, know what it means and are even expecting it. Beware, do not confuse your users!

No comments:

Post a Comment