As a small disclaimer, I'm pretty new to iOS Dev and have mainly worked with Appcelerator Titanium in the past, so this may be pretty basic.

Currently I'm in the middle of trying to create a page in an iPhone app that pulls data from an external API. That API returns a JSON array of objects that I'm using to populate a table (pretty standard behavior).

Each hash in the array contains of squares that I need to display in the table view and thy are formatted different based on the number of squares. For example:

  • If one comes back the table view cell contains a name and a single large square.
  • If two come back the table view cell contains a name two slightly smaller squares positioned overlapping.
  • If three come back the table view cell contains a name three slightly smaller squares positioned shaped like a triangle.
  • If four come back the table view cell contains a name four slightly smaller squares positioned in the shape of a square.
  • If more than for come back the table view cell contains a name, four slightly smaller squares and the last square has a +x count for how many there are in addition to the first 3.

  • Note: The name is in the exact same place on each cell.

So the real question is it seems like I'm not sure which of these two options are the best way to go:

  1. Create 5 different SpecificCell.xib files (along with .h and .m files) and in cellForRowAtIndexPath create one of those and return it. This seems like a LOT of duplicate code for name, etc. and in general just a ton of code (15 new files) for something that realistically only changes a part of the cell (Name remains in the exact same spot, only the square images change).

  2. Create a single Cell.xib (along with .h and .m files) and pass the dict to a new function that returns a parent view and the child square views, then add those to the cell in cellForRowAtIndexPath.

My main concern, and I'm curious what actual Objective-C developers tell me here haha, is do I receive memory benefits from using the first approach because the app already knows in memory how to create a cell with those exact views?

Or, is there a third way I don't know yet?

Related posts

Recent Viewed