The easiest method is to set the tableFooterView
property:
- (void)viewDidLoad
{
[super viewDidLoad];
// This will remove extra separators from tableview
self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
}
You could add this to your TableViewController (this will work for any number of sections):
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
// This will create a "invisible" footer
return 0.01f;
}
and if it is not enough, add the following code too:
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
return [UIView new];
// If you are not using ARC:
// return [[UIView new] autorelease];
}
override func viewDidLoad() {
super.viewDidLoad()
tableView.tableFooterView = UIView() // it's just 1 line, awesome!
}
You can achieve what you want by defining a footer for the tableview. See this answer for more details:Eliminate Extra separators below UITableView
Using the link from Daniel, I made an extension to make it more usable:
//UITableViewController+Ext.m
- (void)hideEmptySeparators
{
UIView *v = [[UIView alloc] initWithFrame:CGRectZero];
v.backgroundColor = [UIColor clearColor];
[self.tableView setTableFooterView:v];
[v release];
}
After some testings, I found out that the size can be 0 and it works as well. So it doesn't add some kind of margin at the end of the table. So thanks wkw for this hack. I decided to post that here since I don't like redirect.
Swift Version
The easiest method is to set the tableFooterView property:
override func viewDidLoad() {
super.viewDidLoad()
// This will remove extra separators from tableview
self.tableView.tableFooterView = UIView(frame: CGRectZero)
}
For Swift:
self.tableView.tableFooterView = UIView(frame: CGRectZero)
For newest Swift:
self.tableView.tableFooterView = UIView(frame: CGRect.zero)
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