iOS detailed TableView: Performance optimization and hand-drawn UITableViewCell

Source: Internet
Author: User

Improve the performance of table views

UITableView as the most commonly used view in the application, its performance optimization problems are almost always mentioned. The following are some of the main explanations for the performance optimization of table views in non-network access situations:

1. When customizing a class or Xib file

When system-provided styles don't meet us, we often create custom classes or xib files to customize cell styles.

Before, we usually use the old method to set up reuse in the loadnib way or in the proxy method, and manage the cache pool. After IOS6, we can register the cell or even the header view by registering, let the system manage more efficiently.

2.InterfaceBuilder

It is said that there are a lot of paranoid engineering lions insist on hand code to complete the project, hate drag and drop dragging. But as the IB continues to grow, more and more people are liking the use of IB to build and manage interfaces. In the new XCODE5, IB has made a lot of progress. Back to the point, however, it is recommended that you use code to create a cell class when using a high-performance cell. When UITableViewCell has more than one child view, the rendering mechanism of iOS slows down. overriding drawrect to draw content directly can improve performance rather than initializing some label or ImageView when class initialization.

3. Layer Color problem

Transparent layers have a certain effect on the rendering performance, and the system must compute the color and draw it by mixing the transparent layer with the view below. Reducing transparent layers and using opaque layers to replace them can greatly improve rendering speed.

4. Issues to be noted in rendering

As much as possible to avoid allocating resources when drawing, such as Uifont,nsdateformatter or any object that is needed for drawing, it is recommended that you perform the assignment in the initialization method of the class hierarchy and store it as a static variable.

5. For the agent method thin body

We can often see in the project,

-(UITableViewCell *) TableView: (UITableView *) TableView Cellforrowatindexpath: (Nsindexpath *) IndexPath

The code in this method is much more frightening, and we can say that some data is bound to the cell, or when there are multiple tableview, bind it to another tableviewcontroller. This can facilitate maintenance and management, in fact, the program also has a great help in running performance.

Draw cells manually

A table view cell is drawn below and displayed in the table view.

Related Article

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.