prepareForSegue not called from custom uitableviewcell

后端 未结 1 876
感动是毒
感动是毒 2020-12-11 06:52

I have a custom TableViewController with a custom TableViewCell. I created a segue on the storyboard from the Cell to another ViewController to display the details but prepa

1条回答
  •  长情又很酷
    2020-12-11 07:27

    Drag the segue from the TableViewController in InterfaceBuilder, not from the cell. Then you can perform the segue with its identifier in didSelectRowAtIndexPath via performSegueWithIdentifier.

    Also check the function signatures. The exclamation marks for implicitly unwrapped optionals are no longer needed:

    func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
        let cell = tableView.cellForRowAtIndexPath(indexPath)
        tableView.deselectRowAtIndexPath(indexPath, animated: true)
        performSegueWithIdentifier("mySegue", sender: cell)
    }
    
    override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    }
    

    0 讨论(0)
提交回复
热议问题