Post

Replies

Boosts

Views

Activity

UITableView calls numberOfRowsInSection multiple times, why?
Hello - During my App's startup as with most any App with a UITableView with Sections, numberOfSections is called -    func numberOfSections(in tableView: UITableView) -> Int {    return fetchedResultsController.sections?.count ?? 0   } as you can see, the number provided by the fetchResultsController is returned, which in my current case, returns 81. Then    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int is called once for each of the 81 sections, OK, I'm not sure why it needs all 81 counts at once, perhaps the first couple screen fulls would suffice, but then, it's called again, and again, and again until numberOfRowsInSection has been called 480 times. That seems a bit excessive, wouldn't you agree? Meanwhile, viewForHeaderInSection has been called 16 times for the 4 sections currently visible. This can't be working as designed, can it? Is there some reason UITableView can't rely on the answers it receives the first time? I've searched and tried every solution (suggestion) I've found on StackOverflow to no avail. Obviously I'm missing something, maybe a well hidden delegate call that should be answered to thwart this repeated cycle of insanity - tableView apparently thinks doing the same thing over and over will yield different results. Hope you can help, thank you for your time.
7
0
1.4k
May ’22