- 1.Create a custom UITableView with loading indicator
- 2.Remove the UITableViewCell separator for empty cells
- 3.Custom UITableView with empty view
Today I’m going to show you all a pretty basic and standard thing that you should always do in your projects. This became now standard, but still a lot of developers don’t know how to do, or just don’t care about it.
And this is removing those separators for empty cells.
As you can see by default you have those separators there, no matter you don’t have anything inside that cell.
If you use taller cells, it’s okay, like in this example, but if your cells’ height is 44pt or around that, you’ll see a lot of those separators. And that’s just look unprofessional.
How to remove UITableViewCell separator for empty cells?
There are several ways to fix this issue.
- Set the Separator type to None in Interface Builder.
- Select your UITableView, in the Attributes Inspector (Right sidepanel), select the Separator and from the dropdown menu change it to None.
- This way though, it will not show any separators.
- Just fix it programmatically:
tableView.tableFooterView = UIView(frame: CGRectZero)
This is all you have to do. Put it into viewDidLoad() method and you are good to go. You’ll notice that those empty UITableViewCell separators are gone.
And since you don’t want to do it everywhere in your code, you can just create a BaseTableView (subclassed from UITableView) and for example in its’ awakeFromNib() method, call this code. So you can use it everywhere without adding this line again.
I know for some/lot developers it wasn’t very useful, since they knew this trick already, but I hope I could help someone who just started learning iOS and couldn’t figure out how to get rid of those ugly lines.