0

I'm looking to improve my way of working, as I seem to be using a pattern that might be "best in class", or there is a much better way of doing it. Looking for advice.

Context: I need to show many types of rows: headers, totals, customers, projects, etc, but the counts and sequences change.

Calculating which row was what became to complex.

So I created a dataObject that represents possible cell content, with an enum type, indicating what cell content this specific dataObject represents.

(pseudocode)

dataobject:NSObject{
    @property cellType 
    @property... storage for other info relevant to the eventual CustomCell
}

I than generate an array with many dataObjects in the relevant sequence:

  - dataObject {cellType = header}
   - dataObject {celltype = customer}
   - dataOb.....

number of rows this way is equal to the object count.

I generate the UITableviewCell by retrieving the dataObject at the specific index, check what type it is, and return a CustomCell of that type.

I even use the dataObject as a multifunctional container, to contain information needed to be displayed in the cells. As all Cells have a common parent, they know how to read a dataObject,and display the information for their specific CustomCell type.

I hope it's clear...

anyone know a better solution ?

4

0 回答 0