I understand that UITableView
will call -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
method to get each of the cells for the table view. Say I have my data source is fetched over the internet and I have to account for latency. What will be the best way of "stopping" this method from being called? Should it block on a boolean flag in the application? Should I just call cellForRowAtIndexPath
again from within my application?
I am uncertain as to when the function gets called, ie, how often the UITableView
"refreshes" itself. Any explanations will be helpful! Thanks!
willDisplayCell: used here for smoother UI (single cell usually displays fast after willDisplay: call). You could also try it with tableView:didEndDisplayingCell: . Much better for knowing when all the cells load that are visible. However this will be called whenever the user scrolls to view more cells.
reloadData()Reloads the rows and sections of the table view.
Overview. Table views manage only the presentation of their data; they don't manage the data itself. To manage the data, you provide the table with a data source object — an object that implements the UITableViewDataSource protocol. A data source object responds to data-related requests from the table.
There are two main base ways to populate a tableview. The more popular is through Interface Building, using a prototype cell UI object. The other is strictly through code when you don't need a prototype cell from Interface Builder.
If you don't have data, or you don't have the data for additional cells, then cellForRowAtIndex:
will not be called as long as you don't tell the UTableView that you have rowCounts or new rowCounts. That value is being set in numberOfRowsInSection:
.
In other words, don't report any new cells in numberOfRowsInSection:
, until you actually have that data in hand, and then cellForRowAtIndexPath:
won't be called prematurely.
When you do get the additional row data, then call reloadData
to get the UITableView to ask for the number of rows and then call cellForRowAtIndex:
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With