What's the best way to return different cells depending on position in a UITableView
Posted
by Robert Conn
on Stack Overflow
See other posts from Stack Overflow
or by Robert Conn
Published on 2010-03-15T22:57:24Z
Indexed on
2010/03/15
22:59 UTC
Read the original article
Hit count: 187
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?
© Stack Overflow or respective owner