-2

I have a UITableViewDataSource that return 6 in the func

tableView(UITableView, numberOfRowsInSection: Int)

Oddly enough the func

tableView(UITableView, cellForRowAt: IndexPath)

it is executed only 5 times and I have only 5 cells created and one is missing. This happens only in one orientation. in the other I get 6 cells constructed It's the first time I see this, why can this happen?

rmaddy
  • 314,917
  • 42
  • 532
  • 579
onthemoon
  • 3,302
  • 3
  • 17
  • 24
  • 1
    Only visible cells will be created at first, while you scroll the cells will get re-used/initialised for the remaining ones. Read the doc here]: https://developer.apple.com/documentation/uikit/uitableview/1614983-cellforrowatindexpath?language=objc – Midhun MP Oct 28 '19 at 16:02

1 Answers1

1
  • It's not a bug but a feature. CellForRowAt will be called only they need to show a certain index cell.

  • Let's say your data source returns 100. These 100 cells won't be
    created in one go. But it will only be created when you scroll them.

  • Its happening in one orientation because in that orientation, all of your cells are not visible on the screen.

You can check this post for detailed explanation When is cellForRowAtIndexPath method called?

Ankit Saxena
  • 809
  • 7
  • 10