RoundOutTooSoon RoundOutTooSoon - 1 year ago 97
iOS Question

Eliminate extra separators below UITableView

When I set up a table view with 4 rows, there are still extra separators lines (or extra blank cells) below the filled rows.

How would I remove these cells?

tblView = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain];
[tblView setDelegate:self];
[tblView setDataSource:self];
[tblView setSeparatorStyle: UITableViewCellSeparatorStyleSingleLine];

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return 4;

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];

int row = [indexPath row];

return cell;

Answer Source

Interface builder (iOS 9+)

Just drag a UIView to the table. In storyboard, it will sit at the top below your custom cells. You may prefer to name it "footer".

Here it is shown in green for clarity, you'd probably want clear color.

Note that by adjusting the height, you can affect how the "bottom bounce" of the table is handled, as you prefer. (Height zero is usually fine).

enter image description here


override func viewDidLoad() {
    self.tableView.tableFooterView = UIView()


iOS 6.1+

- (void)viewDidLoad 
    [super viewDidLoad];

    // This will remove extra separators from tableview
    self.tableView.tableFooterView = [UIView new];

or if you prefer,

    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

Historically in iOS:

Add to the table view controller...

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
     // This will create a "invisible" footer
     return 0.01f;

and if necessary...

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
    return [UIView new];

    // If you are not using ARC:
    // return [[UIView new] autorelease];