iOS TableView performance optimization/tableview sliding?

Source: Internet
Author: User

This paper focuses on the following several points to expand the TableView performance optimization of the discussion?

1.UITableViewCell reuse mechanism?

2.tableView sliding why would chuck?

3. How to optimize?

4. Summary

1.UITableViewCell reuse mechanism?

UITableView only creates one screen (or more than one screen) of cells, and the others are removed for reuse. Each time the cell slides out of the screen, it is placed in a collection, and when it is displayed to a cell in a certain location, it is first taken out of the collection, and if so, it is directly displayed and not created.

2.tableView sliding why would chuck?

When the cell assigns the content, it will set the layout according to the content, can know the height of the cell, if there are 1000 rows, it will call 1000 times the Cellforrow method, and our processing operation of the cell is in this method to assign value, layout and so on, the overhead is very big.

3. How to optimize?

3.1 Optimization: The Heightforrow method handles the cell height.

Idea: Assignment and calculation layout separation. Cellforrow is responsible for assigning values, and Heightrorrow is responsible for calculating heights.

3.2 Custom Cell Drawing:

Each information is drawn based on a previously calculated layout. Requires an asynchronous drawing. Overriding the Draerect method does not require an asynchronous drawing, because DrawRect is originally drawn asynchronously. The drawing of the picture-text mixed row, Coretext drawing.

3.3 Load on Demand (Uiscrollview aspect):

If the target row differs from the current row by more than the specified number of rows, only n rows are loaded before and after the target scroll range. When scrolling is fast, only the cells in the target range are loaded, so loading on demand can greatly improve fluency.

4. Summary

1. Calculate and cache the height in advance because Heightforrow is the most frequent call.

2. Asynchronous drawing, Encounter complex interface, performance bottleneck, may be a breach.

3. Load on demand when sliding, this is useful when a large number of pictures are displayed and the network is loaded. (Sdwebimage has implemented asynchronous loading).

4. Reuse cells.

5. If the content in the cell is displayed from the Web, the result request is cached using asynchronous loading.

6. Use less or no transparent layers, using opaque views.

7. Try to make all view opaque, including the cell itself.

8. Reduce Subviews

9. Use less AddView to dynamically add view to the cell, add it when initialized, and then control whether it is displayed via hide.

iOS TableView performance optimization/tableview sliding?

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.