UITableVIew: optimized rolling smoothness and uitableview scrolling
Reasons for affecting the smoothness of UITableViewUITableView scrolling:
1. Too much computing in the proxy method takes up the time of the UI thread
2. Same as above
3. The structure of the view in the Cell is complex. For example, using layer does not have much impact. However, if the layer is transparent, or has rounded corners, deformation, and other effects, the rendering speed will be affected.
First of all, we need to understand the sequence of call and timing of the tableview proxy (the method set of datasource and delegate, the same below. For general applications, the order is as follows:
1. Ask the proxy for number Of Rows.
2. For each Row, the height For Row At Index Path is required For the proxy.
3. The cell For Row At Index Path to be visible to the proxy on the current screen. (The number of mobile phones with a 4-inch screen displayed in actual measurement is + 2, and the number of 3.5-inch screen is the same as that of 4-inch screen, although the number of cells displayed on a 3.5-inch screen is smaller than 4-inch !)
4. The cell is displayed.
TableView: heightForRowAtIndexPath:
Many people put the focus of optimization in the cell for row at indexpath method. Here, we try to calculate as little as possible, however, it ignores another method that can easily increase the loading time:
For height calculation, note that if the row height is fixed, delete tableView: heightForRowAtIndexPath: Method in the proxy and set the rowHeight attribute of Table View, similar numberOfRowsInSection: I won't write them all. This can also reduce the call time.
When creating the tableView method, set the Row Height to the rowHeight attribute of the Table View.
// Set the Row Height of tableView to 50. Do not write the proxy method. If the height is different, use this method only when the row height is the same.
Self. tableView. rowHeight = 50;