Optimize the performance of tableView (for the phenomenon of card sliding), tableview sliding
Optimize tableView performance (for the phenomenon of card sliding)
In iOS apps, UITableView should be one of the most frequently used views. IPod, clock, calendar, memo, Mail, weather, photos, phones, text messages, Safari, App Store, iTunes, and Game Center charts can be seen in almost all built-in applications, see its importance.
However, when using third-party applications, performance problems are often encountered, which are generally manifested in comparison cards during scrolling, especially when table cells contain images.
In fact, this problem will not happen if you optimize it in a targeted manner. If you are interested, you can refer to LazyTableImages, an official example program. Although you want to download images from the Internet and display them, they are not stuck during scrolling.
The following describes my understanding of UITableView. However, because I am also a beginner, I may be wrong or missing some, so it is for reference only.
First, let's talk about the principle of UITableView. If you are interested, please refer to "About Table Views in iOS-Based Applications".
UITableView is a subclass of UIScrollView. Therefore, it can automatically respond to rolling events (generally upstream and downstream scrolling ).
It contains 0 to multiple UITableViewCell objects, and each table cell displays its own content. When a new cell needs to be displayed, tableView: cellForRowAtIndexPath: is called to obtain or create a cell. If it is not visible, it is released. It can be seen that at the same time, you only need to have a cell object on the screen, and you do not need to create a cell for each row.
In addition, UITableView can be divided into multiple sections. Each section can have its own head, foot, and cells. When locating a cell, two fields are required: the section in which the cell is located and the row in which the cell is located. This is expressed in the iOS SDK using NSIndexPath. UIKit adds indexPathForRow: inSection: This creation method to it.
Other content, such as editing, will not be mentioned because it is irrelevant to this article.
After introducing the principles, we will start to optimize them.