Performance optimization for iOS development UITableView

Source: Internet
Author: User

One,. Reusing cells

In the data source method, repeat the drawing on the visible page

oc Method -(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath; Swift method override func TableView (Tableview:uitableview, Cellforrowatindexpath Indexpath:nsindexpath)- > UITableViewCell

Therefore, you can do some processing in this method

Static NSString *  "reusedcellid";   * Cell =private"reusedcellid"= Tableview.dequeuereusablecellwithidentifier (Reusedcellid, Forindexpath:indexpath)

This will prevent the cell from being created indefinitely, reusing the cell

  

Second, the cell image asynchronous loading

When the image is loaded asynchronously, the picture of the cell is executed in the child thread, but if it declines at this point, there will be a lag.

Workaround:

Download the image in the following two ways,

// when the drag is over -(void) scrollviewdidenddragging: (Uiscrollview *) ScrollView willdecelerate: (BOOL) decelerate//  deceleration time -(void) scrollviewdidenddecelerating: (Uiscrollview *) ScrollView

Specific operation:

 //  Gets the visible part of the object  Nsarray *visiblepaths = [Self.tableview indexpathsforvisiblerows];  for   (Nsindexpath *indexpath in   Visiblepaths) {  //  Gets the DataSource inside the object, And that you do not need to load the  <code>-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) Indexpath 
{
if (self.tableView.dragging = = NO && self.tableView.decelerating == NO) { // Span style= "color: #008000;" > start loading the picture asynchronously
<code>}


Third, minimize the use of transparent layers

The internal rendering mechanism

Performance optimization for iOS development UITableView

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.