0

So I have a piece of code

  let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("SampleNameCell")! as UITableViewCell


       // cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "SampleNameCell")

The top line of code works and creates the table cell. When the cell is clicked, a view opens up that I associate with the identifier. However when I uncomment the code so that I can add a right detail label to the cell, the right detail label shows but now the view does not appear when clicked. This is the uncommented code that creates this problem

  cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "SampleNameCell")

Any help would be appreciated, thanks!

rmaddy
  • 314,917
  • 42
  • 532
  • 579
timedwalnut
  • 94
  • 1
  • 13
  • 2
    I don't understand what you're trying to do. – azizj Feb 20 '17 at 23:00
  • What is triggering the action based on clicking the cell? If this is something in the Storyboard, then your commented out line is replacing the cell created from the storyboard, which everything you might have set up in the storyboard, with a plain one created in code. – Gary Makin Feb 20 '17 at 23:03
  • you can't set an existing cell's style . you have to do it problematically – Nazmul Hasan Feb 20 '17 at 23:05
  • @AzizJaved I want a cell that displays right and left label on the cell that when clicked opens up a view – timedwalnut Feb 21 '17 at 00:10

1 Answers1

0

I'm assuming you're using a storyboard to configure your cell. To set up a cell with a right detail, it should look like this…

enter image description here

To trigger a segue to another view controller on tap, drag from your cell to the next view controller…

enter image description here

In your table view controller, you should have code like…

override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    let cell = tableView.dequeueReusableCell(withIdentifier: "SampleNameCell", for: indexPath)

    // Configure cell here

    return cell
}

Note the , for: indexPath) in the method signature.

Ashley Mills
  • 50,474
  • 16
  • 129
  • 160