IOS8 UITableView split bar setting separator intent = 0 does not work
When ios7 is used, separator intend = 0 of TableView can be set on storyboard to pin the split entries of tableview to the header.
However, when ios8.
Google found the answer in stackoverflow
Translation record
IOS8 introduces the layoutMargins attribute in cell and tableview, and this attribute does not exist in iOS 7, so you need to treat the two versions differently.
Use the Ricky solution to set the layoutMargin attribute in the cell:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ if ([cell respondsToSelector:@selector(setSeparatorInset:)]) { [cell setSeparatorInset:UIEdgeInsetsZero]; } if ([cell respondsToSelector:@selector(setLayoutMargins:)]) { [cell setLayoutMargins:UIEdgeInsetsZero]; }
// Add the following paragraph according to the author's final meaning.
If ([cell respondsToSelector: @ selector (setPreservesSuperviewLayoutMargins :)]) {
[Cell setPreservesSuperviewLayoutMargins: NO];
}
}
You also need to set the same attribute in tableview. through multiple experiments, I found that you can set this attribute in viewDidLayoutSubviews.
Copy the following code to your view implementation.
-(void)viewDidLayoutSubviews{ [super viewDidLayoutSubviews]; if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) { [self.tableView setSeparatorInset:UIEdgeInsetsZero]; } if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) { [self.tableView setLayoutMargins:UIEdgeInsetsZero]; }}
In this way, you can split the headers in ios7 and iOS 8. Ios6 is the top header by default, so this solution can be applied to ios6-8 ).
Edit: According to @ bffmike on Twitter, you may also need to set preservesSuperviewLayoutMargins = NO in the cell. Note that the situation varies from person to person.