IOS - How expensive is reloadData?

I am wondering how expensive reloadData on a tableView is. I wanted to update the table view every 5 seconds. Will it cause performance problems?

+4
source share
3 answers

Reload the data, call the two main methods in your table view data source, numberOfRowsInSection , and then go to cellForRow:atIndexPath: for visible cells, depending on your tableView contentOffset

If your application scrolls well already, then the only performance striking for your application will continue if you do a lot of work in numberOfRowsInSection (for example, hit the network or something a lot of time).

Edit: As already noted, heightForRow:atIndexPath: can also be a pain point if you use it to perform complex calculations for different height cells.

+4
source

In addition to @Jessedc's answer,

If all your rows have the same height, then heightForRowAtIndexPath more expensive than tableview.rowHeight .

If you have many rows with different heights for each row, and you calculate the row height every time the heightForRowAtIndexPath method is heightForRowAtIndexPath , then this is even more expensive.

There are many factors that influence how expensive a reloadData call reloadData . It all depends on what and how much you do each time delegate methods are called.

0
source

If applicable to your situation, NSFetchedResultsController may notify your table view when data changes, rather than updating it every "n" seconds.

0
source

Source: https://habr.com/ru/post/1434088/


All Articles