I was trying to understand why numberOfSectionsInTableView is being called multiple times each time I update my data source. From the stack trace in gdb, I see the following
#0 -[JobPickerTVC numberOfSectionsInTableView:] (self=0x4d61fe0, _cmd=0x6207f5, tableView=0x6034800) at JobPickerTVC.m:153
#1 0x003d66ff in -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] ()
#2 0x003d63b0 in -[UITableViewRowData invalidateAllSections] ()
#3 0x00299010 in -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] ()
#4 0x002891e8 in -[UITableView endUpdates] ()
#5 0x000050c8 in -[JobPickerTVC controllerDidChangeContent:] (self=0x4d61fe0, _cmd=0x17109d, controller=0x4da5e40) at JobPickerTVC.m:442
followed by
#0 -[JobPickerTVC numberOfSectionsInTableView:] (self=0x4d61fe0, _cmd=0x6207f5, tableView=0x6034800) at JobPickerTVC.m:153
#1 0x003d66ff in -[UITableViewRowData(UITableViewRowDataPrivate) _updateNumSections] ()
#2 0x003d6417 in -[UITableViewRowData ensureAllSectionsAreValid] ()
#3 0x0029902e in -[UITableView(_UITableViewPrivate) _endCellAnimationsWithContext:] ()
#4 0x002891e8 in -[UITableView endUpdates] ()
#5 0x000050c8 in -[JobPickerTVC controllerDidChangeContent:] (self=0x4d61fe0, _cmd=0x17109d, controller=0x4da5e40) at JobPickerTVC.m:442
From what I can tell, the code executes [UITableViewRowData invalidateAllSections] (line #2 of the first trace) and then [UITableViewRowData ensureAllSectionsAreValid] (line #2 of the second trace). Both of these end by calling [JobPickerTVC numberOfSectionsInTableView:]. So [JobPickerTVC numberOfSectionsInTableView:] is getting called twice. I would like to know why this is happening and what these operations are doing.
There’s one more call to numberOfSectionsInTableView for another reason, but I would like to understand these first.
Your table numberOfSectionsInTableView is getting called multiple times because you are reloading your table data.whenever you reload table,this method will check for all delegates of tableview.