-1

In my storyboard I created two different prototype cells, cell1 and cell2. I want them to appear in my tableView like this:

TableView

prototype cell1 - indexpath.row[0]
prototype cell2 - indexpath.row[1]
prototype cell1 - indexpath.row[2]
prototype cell2 - indexpath.row[3]
and so on...

I experimented with if and switch statements and for loops in cellForRowAtIndexPath:, but couldn't get it right. Then I searched here and on the internet but still couldn't find an answer. Hopefully someone could explain it to me?

jscs
  • 63,694
  • 13
  • 151
  • 195
Nielsapp
  • 302
  • 1
  • 11

1 Answers1

0

This is simple to do with the mod operator and a single if statement,

if (indexPath.row %2 == 0) {
    //dequeue cell1 type
    // configure the cell
    // return cell

}else{
    //dequeue cell2 type
    // configure the cell
    // return cell
}
rdelmar
  • 103,982
  • 12
  • 207
  • 218