0

I use a dynamic tableViewController. I implement the numberOfSection to return 4, and the numberOfRowInSection return 1. These are the only changes I made for the blank TableViewController. But when I run it on simulator, it shows multiple cells, which I expected to be only four cells. Why is that?

Note: If I change the height of each cell to let the screen only fit four cells at a time, it will work fine since it won't let be me scroll down. So I guess is the tableViewController always try to fill the screen no matter how many cell it should display?

Victor Sigler
  • 23,243
  • 14
  • 88
  • 105

2 Answers2

1

Yes, the UITableView will always continue to fill the screen with 'empty' cells of the default row height. To prevent this, you could add the following code in viewDidLoad:

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

(For Swift, check @VictorSigler's answer.)

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
0

In Swift:

self.tableView.tableFooterView = UIView(frame: CGRect.zeroRect)
Victor Sigler
  • 23,243
  • 14
  • 88
  • 105