Utku Dalmaz Utku Dalmaz - 7 months ago 8
Swift Question

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?

Answer

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

}
Comments