Lists are probably one of the UI controls that we deal with most in APP development, and their importance is self-evident. Optimizing their performance is also crucial. For iOS development, a list is what we call a UITableView/UICollectionView. In the live APP development, the hour hand is naturally essential for the optimization of the list.

Here is a brief introduction to list optimization ideas using UITableView as an example.

(1) Cell reuse. This is a part of the game that every iOS developer is familiar with. We often bind data for each cell in cellForRowAtIndexPath:, actually calling cellForRowAtIndexPath: In tableView: willDisplayCell: forRowAtIndexPath: tableView: willDisplayCell: forRowAtIndexPath: Bind data in the willDisplayCell method. Notice that willDisplayCell will be called before the cell is displayed in the TableView. At this point, the cell instance has been generated, so you cannot change the structure of the cell, but only change some attributes of the UI on the cell (such as the content of the label).

(2) Reduce the number of views. When we add system controls to the cell, in fact, the system will call the underlying interface for drawing. Adding a large number of controls will consume a lot of resources and affect the performance of rendering. Using the default UITableViewCell and adding controls to its ContentView can be very performance consuming. In addition, when initializing the cell, try to create all the contents that need to be displayed, and then display or hide them as required. Do not create controls dynamically.

(3) Asynchronous operation. We often see the phenomenon that the whole page is stuck when loading, no matter how much click, as if the machine has crashed. The main thread is blocked. Therefore, for the request of network data or the loading of pictures, we can open multithreading and put the time-consuming operation into the sub-thread for asynchronous operation.

(4) Load on demand. When sliding quickly, only cells within the target range are loaded, which is loaded on demand (in conjunction with SDWebImage) to greatly improve fluency. Here’s a simple example:



Of course, don’t forget to add the following lines to the cellForRowAtIndexpath: proxy method



For the technical staff of software companies specializing in the development of live streaming apps, list optimization is often used. Of course, if other APP development uses the same control, this optimization idea is also applicable.