All the tableViews
of my app are not respecting the property
SeparatorInset
- Custom
- left = 0
on storyBoard
. It was all working fine on iOS 7
, but not anymore.
When I implement the two below methods:
-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath
{
// iOS 7
if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
[cell setSeparatorInset:UIEdgeInsetsZero];
}
// iOS 8
if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
[cell setLayoutMargins:UIEdgeInsetsZero];
}
}
-(void)viewDidLayoutSubviews
{
// iOS 7
if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
[self.tableView setSeparatorInset:UIEdgeInsetsZero];
}
// iOS 8
if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
[self.tableView setLayoutMargins:UIEdgeInsetsZero];
}
}
It works correctly, I just don't understand why I can't keep setting this on storyboard
which is much simpler.
Any thoughts?
This code may help you. Include both layoutMargins and separatorInset, to support both iOS versions 7,8 For iOS8:
First configure your table view as follows:
if ([self.tableView respondsToSelector:@selector(layoutMargins)]) {
self.tableView.layoutMargins = UIEdgeInsetsZero;
}
Then in your cellForRowAtIndexPath: method, configure the cell as follows:
if ([cell respondsToSelector:@selector(layoutMargins)]) {
cell.layoutMargins = UIEdgeInsetsZero;
}
For version check you can use following things:
#if __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000
if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
cell.layoutMargins = UIEdgeInsetsZero;
}
#endif
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With