What's the best way to return different cells depending on position in a UITableView
- by Robert Conn
I have a grouped UITableView that has 3 sections and a number of cells in each section that each need to be a different custom cell, with different display requirements.
I currently have a large if statement in cellForRowAtIndexPath, with each branch instantiating and returning the appropriate custom cell based on interrogating the indexPath's section and row properties. e.g.
if (indexPath.section == 0 && indexPath.row == 0) {
// instantiate and return cell A
} else if (indexPath.section == 1 && indexPath.row == 2) {
// instantiate and return cell B
} //etc etc
What is best practice for this scenario? A large if statement does the job, but is it the best implementation?