None of these solutions work on the iPad, but I have come up with a solution that covers both devices:
With reusable cells:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
...[other code]...
[cell setLayoutMargins:UIEdgeInsetsZero];
[cell setSeparatorInset:UIEdgeInsetsZero];
return cell;
}
With non reusable cells:
- (void)removeSeparatorInset:(UITableView*)tableView{
NSArray *cells = [tableView visibleCells];
for (UITableViewCell *cell in cells){
[cell setLayoutMargins:UIEdgeInsetsZero];
[cell setSeparatorInset:UIEdgeInsetsZero];
}
}
-(void) viewDidLayoutSubviews{
[super viewDidLayoutSubviews];
[self removeSeparatorInset:self.tableView];
}
Just to expand on this approach:
@property(nonatomic) UIEdgeInsets separatorInset;
@property(nonatomic) UIEdgeInsets layoutMargins;
Both properties can be used by UITableView
& UITableViewCell
.
The latter is, in fact, a property of UIView
, which is a parent class of both UITableView
& UITableViewCell
.