Another option is to subclass UITableView :
@synthesize hideLastSeparator = _hideLastSeparator; @synthesize hideLastSeparatorView = _hideLastSeparatorView; -(void)setHideLastSeparator:(BOOL)hideLastSeparator { if (_hideLastSeparator == hideLastSeparator) { return; } _hideLastSeparator = hideLastSeparator; if (_hideLastSeparator) { _hideLastSeparatorView = [[UIView alloc] initWithFrame:CGRectMake(0, self.contentSize.height, self.bounds.size.width, 0.5f)]; _hideLastSeparatorView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleBottomMargin; _hideLastSeparatorView.backgroundColor = self.backgroundColor; [self addSubview:_hideLastSeparatorView]; [self hideSeparator]; } else { [_hideLastSeparatorView removeFromSuperview]; _hideLastSeparatorView = nil; } } -(void)setContentSize:(CGSize)contentSize { [super setContentSize:contentSize]; if (_hideLastSeparator) { [self hideSeparator]; } } -(void)hideSeparator { CGRect frame = _hideLastSeparatorView.frame; frame.origin.y = self.contentSize.height - frame.size.height; _hideLastSeparatorView.frame = frame; }
.h should only contain property declarations for hideLastSeparator and hideLastSeparatorView .
If you want to hide the delimiter, use the new class and set myTableView.hideLastSeparator = YES .
The way this works is to prevent the last separator by adding a new look to it.
This is somewhat easier to use in my opinion (than using a custom separator or setting the last Inset separator of the last cell) and avoids some strange animations that the tableFooterView setup method sometimes calls (for example, during insert / delete rows or other table animations).
alex-i Aug 24 '16 at 11:10 2016-08-24 11:10
source share