Search code examples
iosiphoneuitableviewnsarray

Is ok to store UITableViewCells into an array?


I want to display the information about an user into table view, some information is not mandatory so finally some cells may not be on the table view. I have the idea of using an array with cells, because I can have maximum 10 cells, and this will simplify the logic, if I will use standard Apple behavior I need to have to many checks and a complicated logic for table view data source and delegate. It's ok to initialise the cells, put them into an array and to display them after?


Solution

  • Sure. For a small number of cells like this, this is fine. You'll still need the data source of course, but it can just pull cells from an array if that works well for you.

    You may also be interested in just using a table view configured with static cells in your Storyboard. You can then hide cells you don't want. See UITableView set to static cells. Is it possible to hide some of the cells programmatically?