ios-Performance Optimization 4

Source: Internet
Author: User

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:

    • Correct use of ' reuseidentifier ' to reuse cells
    • Try to make all the 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, just use it 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

ios-Performance Optimization 4

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.