0

I want the last UITableViewCell to have no separator. All other cells should have a separator that spans the entire width of the table. I have been successful with the first requirement, but unfruitful with the second requirement.

enter image description here

The yellow color is for debugging purposes. It allows you to see the width of the cell, which is the same as the width of the table. As you can see, the separator should not be narrower than cell, because I set the separator insets to zeros.

- (UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    // <typical boilerplate code here>

    cell.backgroundColor = [UIColor yellowColor];

    if ((NSUInteger)(indexPath.row) == self.options.count - 1) {
        cell.separatorInset = UIEdgeInsetsMake(0.0, tableView.width, 0.0, 0.0);
    } else {
        cell.separatorInset = UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0);
    }
}
Pwner
  • 3,714
  • 6
  • 41
  • 67
  • This seems to have been answered here: https://stackoverflow.com/questions/18773239/how-to-fix-uitableview-separator-on-ios-7 – Kiran Oct 07 '14 at 00:38
  • @Kiran : `UIEdgeInsetsZero` is the same is `UIEdgeInsetsMake(0.0, 0.0, 0.0, 0.0)`. I have tried both and both failed to remove the default padding on the left. – Pwner Oct 07 '14 at 01:38
  • Have you tried doing the same from the storyboard as mentioned in http://stackoverflow.com/a/18935521/959654 ? – Kiran Oct 07 '14 at 02:02
  • @kiran and @rmaddy , I was confused about iOS 7 and 8. On 7, you use `separatorInset` to remove the margin. On 8, you use `layoutMargins` to remove it. – Pwner Oct 07 '14 at 18:21

0 Answers0