开发者

UITableView Reusable cells

C开发者_开发知识库an someone explain me the way reusable cells works for single table view?

How many reusable cells a datasource should create? So far in all samples I've seen only one. Would one even need more?


When creating a cell, you pass an identifier for that specific type of cell, so that later, you can try to get a preallocated one and only need to recreate one, if there is not a free one left (done automatically for you - just try to get one with the identifier as in the example code).

You can use as many different identifiers as you like, good practice is to use a different one for every different type of cell (which are probably of different UITableViewCell subclasses anyway).

So if you have CellTypeA and CellTypeB (both inheriting from UITableViewCell or setup very differently), use distinct keys for both types.


The datasource will be asked for one cell every time one is needed. You should therefore only create a new cell if none have previously been cached by the table.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜