1

I have a static table view which contains 1 section with 3 rows. It looks alright in Storyboard, but when running in simulator or in actually iphone, the section contains quite several rows that take up the whole screen, yet only the first 3 rows are tappable, the rest looks like dummy rows just to fill up the screen... So how can I make those dummy rows go away so that only 3 rows (as I asked) would show up?

dulan
  • 1,504
  • 4
  • 20
  • 44

4 Answers4

2

If you are seeing what I think you are, these are not "dummy cells" are just separators. Add this method to your viewDidLoad and check if it fixes:

[self.tableView setTableFooterView:[[UIView alloc] initWithFrame:CGRectZero]];
Roberto Ferraz
  • 2,450
  • 21
  • 43
0

That's the normal look for a UITableView with the plain style:

enter image description here

The empty rows simply have no content and no row events are fired when you tap on them. The rows will fill up the view.

It's OK. Users are used to this, and they can still use the rows to drag/scroll, so it feels natural.

Marcus Adams
  • 49,523
  • 8
  • 81
  • 132
0

Update UITableView Style form Plain to Grouped. Grouped tableview style will remove empty rows from tableview.

Ram Vadranam
  • 460
  • 5
  • 12
0

This is normal for a UITableView.

Try returning a blank UIView in the - (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section method like this:

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    UIView *blankView = [[UIView alloc] initWithFrame: CGRectZero];
    return blankView;
}
Luca D'Alberti
  • 4,434
  • 3
  • 26
  • 41
  • How does adding a dummy header to a section remove the extra rows shown by a table view? – rmaddy Mar 12 '15 at 14:16
  • `UITableView` doesn't create other "placeholder" cells because, if you provide a `UIView` for the footer, tableView expects other contents afte that – Luca D'Alberti Mar 12 '15 at 14:24
  • Yes, I know that adding a footer to the table removes the placeholders. That's fine. But your answer suggests adding a header to each section. Not at all a solution for removing the placeholder rows. – rmaddy Mar 12 '15 at 14:26
  • Oh, I'm sorry, it is my fault, I wrote the wrong method!! I'm editing now – Luca D'Alberti Mar 12 '15 at 14:40
  • Ok, that will work but it's overkill. It's much simpler to just add an empty footer to the table. – rmaddy Mar 12 '15 at 14:45