ios - 关于tableview一个场景的疑问
巴扎黑
巴扎黑 2017-04-17 17:32:55
0
6
377

有一个tablview列表, 打算显示类似通讯录的联系人列表, 右边是A-Z的导航, 可能数据量太大。假如一次从api返回10000个信息, 我的疑问是, 一次初始化10000个cell, 可行吗? 因为数据太多了, 本来想分页读取, 但是这种显示方式, 用分页不太合适。 或者有什么思路?

巴扎黑
巴扎黑

reply all(6)
阿神

First of all, the cells of the system tableView have a reuse mechanism. If you write it according to the standard routine, you will not initialize 10,000 cells at once. If the cells all have the same layout, etc., but the content is inconsistent, it will only be displayed on your screen. These cells in the range

阿神

You can try using local data

Peter_Zhu

The server side needs to be modified, and each request loads about 30-40 pieces of data.
In the front-end tableview, several pieces of data are loaded at a time through drop-down loading.

Peter_Zhu

Look at questions 19 and 20: http://www.henishuo.com/ios-interview-middle-two/

It is definitely not possible to have so many pieces of data at one time. Because tableview inherits from scrollview, and this needs to be calculated to get the contentssize, so how many pieces of data are used as data sources, how many times will the row height be calculated, and then it will be very stuck, or it will take a long time to wait for the first time. .

Recommendation: Only load a small amount of data for the first time, such as 10 or 20 items. Then cache the height, so even if there are 10,000 items, after the height has been cached, there will be no stuck (except for those with a lot of rich text).

Let’s take a look at how to automatically calculate and cache row height in the article!

小葫芦

According to the reuse mechanism of tableviewcell, this seems not to be considered? Run it and try how much memory it occupies...

迷茫

There is no need to consider this issue under the cell reuse mechanism

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template