UITableView Performance Optimization Tips
Table view requires good scrolling performance, otherwise the user will find the artifacts of the animation during scrolling.
To ensure a smooth scrolling of table view, make sure you take the following actions:
- use ' reuseidentifier ' correctly to reuse cells
- try to make all view opaque, including the cell itself
- avoid gradients, picture scaling, background selection
- cache row height
- If the real content within the cell comes from the web, using asynchronous loading, the cache request results
- use ' Shadowpath ' to draw shadows
- reduce the number of subviews
- try not to apply ' Cellforrowatindexpath: ' If you need to use it, use it only once and then cache the result
- Use the correct data structure to store the information
- use ' rowHeight ', ' sectionfooterheight ' and ' sectionheaderheight ' to set a fixed height, do not request delegate
- 1. The most common use is cell reuse, registration reuse identifier
If the cell is not reused, a new cell is recreated whenever a cell is displayed on the screen
If there is a lot of data, it will accumulate a lot of cells. If you reuse a cell, create an ID for the cell
Whenever a cell needs to be displayed, it will go to the buffer pool and look for a cell that can be recycled, if the cell is not re-created
2. Avoid cell re-layout
Cell layout fills and other operations are time-consuming, and are typically created with a good layout
If you can put the cell into a custom class individually, the layout is good when initialized
3. Calculate and Cache cell properties and contents in advance
When we create a data source method for a cell, the compiler does not first create the cell and then set the cell's height
Instead, first determine the height of each cell according to the content, after height determination, and then create the cell to be displayed, when scrolling, whenever the cell into the virtual will calculate the height of the pre-estimate height to tell the compiler, the compiler knows the height, immediately after the cell is created, then call the height of the specific calculation method, This can be a waste of time to calculate the cell outside the display.
4. Reduce the number of controls in the cell
Try to make the cell layout roughly the same, different styles of cell can use the unused reuse identifier, the initialization of the Add control,
Not applicable can be hidden first
5. Do not use Clearcolor, no background color, and do not set the opacity to 0
Rendering takes a long time
6. Using Local Updates
If you only update a group, use reloadsection for local updates
7. Load network data, download images, use asynchronous loading, and cache
8. Use less AddView to dynamically add view to cell
9. Load Cell,cell on Demand when scrolling quickly, load only the cells in the range
10. Do not implement a useless proxy method, TableView only adhere to two protocols
Copyright NOTICE: Welcome Reprint, please paste the source address: http://www.cnblogs.com/iCocos/(iOS DreamWorks)
More exciting please pay attention to github:https://github.com/al1020119?tab=repositories
iOS Development--Practical project summary &uitableview performance optimization techniques