2

I knew this question is old, so many answers was already posted here.

The problem is, the solutions are working fine with iPhone's. But when trying it with iPad, I still faces some issue.

Refer the below images(First one is portrait mode and the second one is in landscape mode).

enter image description here

enter image description here

I used the below code in my view controller where I wrote table view's delegate methods.

-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{

    if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
        [tableView setSeparatorInset:UIEdgeInsetsZero];
    }

    if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [tableView setLayoutMargins:UIEdgeInsetsZero];
    }

   if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
   }
}

Question:

Is there is any way to remove these left empty space of table view's separator in iPad? Should I include any extra check's beyond the iPhone's working code?

Confused!!

Community
  • 1
  • 1
Confused
  • 3,846
  • 7
  • 45
  • 72
  • 1
    Can validate this is a thing. I am currently using.. `cell.separatorInset = UIEdgeInsetsZero; cell.layoutMargins = UIEdgeInsetsZero; cell.preservesSuperviewLayoutMargins = NO;` ... and it works on iPhone, but not iPad. – Aaron Smentkowski Feb 13 '16 at 06:42
  • http://stackoverflow.com/questions/25770119/ios-8-uitableview-separator-inset-0-not-working . Refer this link and you may get your solution – Vatsal Raval Feb 19 '16 at 18:42
  • @AaronSmentkowski Replace the first line with `cell.separatorInset = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: cell.bounds.size.width)` – Aleks N. May 17 '17 at 12:09

1 Answers1

7
  • You may need to set the Table View's cellLayoutMarginsFollowReadableWidth to NO if you want to customize insets or margins. Your mileage may vary, this is not documented very well.

This property only exists in iOS 9 so be sure to check before setting.

if([myTableView respondsToSelector:@selector(setCellLayoutMarginsFollowReadableWidth:)])
{
    myTableView.cellLayoutMarginsFollowReadableWidth = NO;
} 
Vatsal Raval
  • 311
  • 1
  • 9