Reputation: 180
Currently I have a UITableView
. I want to remove the last separator of last cell.
Here is how I do that:
UIView *footerN = [[UIView alloc] initWithFrame:CGRectMake(0, 0, _tblStateGaisou.frame.size.width, 10)];
[footerN setBackgroundColor:[UIColor clearColor]];
tblStateNaisou.tableFooterView = footerN;
This only work on iOS 7, nothing happened on iOS 6.
Does anyone know how to solve the issues ?
Many thanks to any help.
Upvotes: 2
Views: 2255
Reputation: 911
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [[UIView alloc] initWithFrame:CGRectZero];
}
In iOS 7.0, if a table view section has a footer with a non-zero height, then a separator will not be placed on the last row of that section, so just set an empty view as the footer for the desired section and that will accomplish your goal. Worked great for me.
Strangely enough, if you set a height of zero for that same footer view with tableView:heightForFooterInSection: then you lose the effect and the last separator reappears. Be sure to return a non-zero height (e.g. "return 1").
Not sure if this works in iOS 6. It's slightly different than your approach, though (section footer vs table footer).
Upvotes: 0
Reputation: 11
For iOS 7.1
if(indexPath.row == (arrayWithData.count - 1))
{
NSArray *subViews = [[[cell subviews] lastObject] subviews];
for (UIView *view in subViews)
{
if([NSStringFromClass(view.class) isEqualToString:@"_UITableViewCellSeparatorView"]) {
[view removeFromSuperview];
}
}
}
Upvotes: 1
Reputation: 121
The number of separators that are shown is determined by the tableview itself. If you want to remove a single separator, you're going to struggle.
An option would be to remove the separators altogether and include your own separator at the bottom of each cell, omitting any that you don't want to be visible.
Upvotes: 2