开发者

How to load a TableViewCell properly - table view cell array or data array

in front don't ans开发者_如何学Pythonwer if you don't know exactly what you are talking about. I want an exact statement!

.

When loading UITableViewCell's I see two major options. The first, to store the values of each cell in an array and the second to store the whole cell's in that array. (apart CoreData).

Now the question is when to use which?

I know if I save the whole cell in an array it will consume more memory at run time but less computing time displaying the cells (for example by scrolling). When the user scroll it would only take the saved cell and display it. Otherwise the application would get the values and start generating (alloc-init) the cell (or pick one from reuse-pool) and assign the values to the labels and/or images whatever.

Now there is a difference between the amount of cells, the type of cells (e.g. custom cells from nib) and the count how many different types are in the same tableView.

In my application I have a tableView which displays 7-8 cells (nearly static), one with an imageView over the whole cell. But all are custom cells with two labels and the one imageView mentioned above. I get every second new data and have to reload the whole table view which means to create a new tableView-array with new values.

//EDIT: to make sure, this is not a question what I should do in my App, it should be a generally question when to use which.

I think both options are possible but what would be the right way?

Where are the limits or should I ever store the whole cells?

Any apple documentation which says "never use whole cells for storage"?

What are the disadvantages?


The only difference comes from cells that are off-screen. If you store the full list of cells in an array, you're using up memory for every cell even if they're not visible. By storing just the data, only the cells that are currently visible will be taking up memory.

Given that you're only displaying 7-8 cells, I don't think you'll have any issues storing an array of whole cells unless these are very large table cells. (The memory-saving stuff is obviously much more important when you have hundreds or thousands of cells.)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜