Utku Dalmaz
Utku Dalmaz

Reputation: 10172

Segue is not working from static UITableView

I have a TableViewController with static cells

I tried both creating segue from TableViewController and TableView cell (Not at the same time)

However, in both scenario, didSelectRowAtIndexPath was not fired

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        print("select")
    }

I also have embedded collectionviewcontroller

class EventDetail: UITableViewController, UITextFieldDelegate, UICollectionViewDataSource, UICollectionViewDelegate  {

What may be causing this?

Upvotes: 3

Views: 958

Answers (2)

Hasya
Hasya

Reputation: 9898

Check your tableview selection must be single selection, if it is "No selection" then didSelectedRowAtIndex would not get called.

enter image description here

You can download sample code and observe it.

Sample download

Also check

enter image description here

Ideally your cellForRowAtIndex should be like this

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
{
    let cell : CustomCell! = tableView.dequeueReusableCellWithIdentifier("ID_CustomCell", forIndexPath: indexPath)  as! CustomCell

    cell.selectionStyle =  UITableViewCellSelectionStyle.None

    cell.lblData.text = "CustomCell....."
    return cell

}

Swift 4 code

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {

    let cell : CustomCell! = tableView.dequeueReusableCell(withIdentifier: "ID_CustomCell", for: indexPath)  as! CustomCell

    cell.selectionStyle =  .none

    cell.lblData.text = "CustomCell....."

    return cell
}

Upvotes: 8

Ketan Parmar
Ketan Parmar

Reputation: 27438

call performseguewithidentifier from didselectRow if you have created segue from tableviewcontroller. like,

 override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    print("select")
    self.performSegueWithIdentifier("your segue identifier", sender: self)
}

hope this will help :)

Upvotes: 1

Related Questions