简体   繁体   中英

Swift - TableView Cells requires double-taps in non-debug mode

I have a tableview with cells which trigger a segue when selected, taking me to the next view. Everything happens perfectly if I put break-points in the code.

TableView is not the first View in the app. It's is loaded via a segue from the Main Screen of the app via an on-screen button, which surprisingly doesn't exhibit this behaviour(single click works fine first time itself).

However, I need to click a cell "twice"(time difference between the clicks doesnt matter) to select it first time when there are no break-points. Thereon, single clicks are fine. Testing this on my Xcode iPhone simulator.

My Code -

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {

    // Keep track of the Holding selected
    self.selectedHolding = self.portfolio.holdings[indexPath.row]

    // Trigger the segue to the detail view
    self.performSegueWithIdentifier("toHoldingTransactionsSegue", sender: self)
    }
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
     if let actualIdentifier = segue.identifier {
        if actualIdentifier == "toHoldingTransactionsSegue" {
        let holdingTransactionsViewController = segue.destinationViewController as HoldingTransactionsViewController
        holdingTransactionsViewController.holding = self.selectedHolding
        holdingTransactionsViewController.delegate = self
        }
    }

}

Please help.

You should connect the segue to the view controller instead of to the cell. When you connect the segue to the cell directly it bypasses / interferes with didSelectCellAtIndexPath

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM