Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide UITableViewStyleGrouped separator at certain sections

I have a grouped UITableView and I have only one cell at section 0. I just want to hide the separator at the first section. If I use tableView.separator = [UIColor clearColor], it hides all separators. Any ideas?

like image 931
Mustafa Avatar asked Nov 05 '22 18:11

Mustafa


1 Answers

While the original comment is generally the way to do this (roll your own subclass with a separator), iOS7 has given us a new pretty easy way to do it too.

With the addition of separatorInsets on tables in iOS7, UITableViewCell now has a separatorInset property. By giving it a large value larger than the size of the table (such as UIEdgeInsetsMake(0, 320, 0, 0)), you can effectively hide the separator by simply moving it off the screen.

The caveat is that the default, built-in views of a UITableViewCell rely on the separator inset for the horizontal alignment of its content (so the content would also be off the screen and invisible). The way to fix this would be to build your own subviews instead, or set the x origin of the default ones you are using in the layoutSubviews method of your UITableViewCell subclass.

like image 74
Dima Avatar answered Nov 09 '22 10:11

Dima