2
votes

I have tried to set the separator inset on the right. Upon the first run of the project and before scrolling the tableview, everything appears smooth. But then as soon as the scrolling happens once, the separator inset of the last row in each section resizes to take the full width. The code used is as below : In viewDidLoad :

myTable.separatorColor = [UIColor redColor];
[myTable setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 40)];

Inside cellForRowAtIndexPath :

[tableView setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 40)];
cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, 40);

I tried putting the same code in almost all other delegate/datasource methods of UITableView but to no avail.

To do the inset thingy in the headerview of the table, I have added two UILabel upper and lower with restricted frame width in viewForHeaderInSection(height of header being 40):

UILabel *upperBorder = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 280.0, 1.0)];
[upperBorder setBackgroundColor:[UIColor blackColor]];
[headerView addSubview:upperBorder];

UILabel *lowerBorder = [[UILabel alloc]initWithFrame:CGRectMake(0, 39.0, 280.0, 1.0)];
[lowerBorder setBackgroundColor:[UIColor blackColor]];
[headerView addSubview:lowerBorder];

I have put the images before and after scrolling.

Before scrolling : enter image description here

After scrolling : enter image description here

Any help in this regard is appreciated. I simply need to make the table look like the first pic even after scrolling i.e. to retain the edge inset in the right side no matter what. Thanks in advance.

1

1 Answers

1
votes

I have also noticed that the last cell of the section is extended to full length, tableview will draw a separator line above your custom section header. So to hide that separator line, you can add a view to hide this separator.

UIView *hideLineView = [[UIView alloc]initWithFrame:CGRectMake(0, -1, 320, 1)];
hideLineView.backgroundColor = [UIColor whiteColor];
[headerView addSubview:hideLineView];

The whiteColor in above code can be set to your tableview background color.