0

I'm designing a tableview with 3 custom cells. I want to customize them by adding unique accessory Type. I've crated a tableViewController with static cells. Each cell I wrote a special Identifier and special class.

How should my tableView fund looks like for 3 custom cells?

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let CityCellIdentifier = "CityTableViewCell"

    let cell = tableView.dequeueReusableCellWithIdentifier(CityCellIdentifier, forIndexPath: indexPath) as! CityTableViewCell
    // Configure the cell...

    return cell
}

should I create three cell variables for that?

Daniel Chepenko
  • 2,229
  • 7
  • 30
  • 56

1 Answers1

0

Per my answer here, use your own variation of the following code:

override func tableView(tableView: UITableView?, cellForRowAtIndexPath indexPath: NSIndexPath?) -> UITableViewCell? {

    if (criteria for cell 1) {
        let cell = tableView!.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as? cell1
        return (cell)
    }
    else {
        let cell = tableView!.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as? cell2
        return (cell)
    }
}
Community
  • 1
  • 1
Shades
  • 5,568
  • 7
  • 30
  • 48