UITableView didSelectRowAtIndexPath sometimes called after second tap

南笙酒味 提交于 2019-11-28 03:19:35

问题


I'm facing a curious UITableView behaviour and i don't know where this is coming from. I'm building a very simple single view IOS8 Swift application with a first ViewController with a UITableView inside it and one custom Image cell. When i tap on a cell it Segue to my SecondViewController.

My UITableView delegate and datasource is connected to the first ViewController. Everything is working except when i tap a cell sometimes i have to tap it twice to trigger the Segue.

Here is my didSelectRowAtIndexPath function:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    println("You clicked on \(indexPath.row) row")
    self.performSegueWithIdentifier("homeToDetail", sender:self)
}

My print is always returning the correct indexPath. Is it a view hierarchy problem or something else ?

Thank you JD


回答1:


Try this.

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
  dispatch_async(dispatch_get_main_queue(), {
    self.performSegueWithIdentifier("homeToDetail", sender:self)
  })
}

This is a bug in iOS 8, I think. UITableViewCell selection Storyboard segue is slow - double tapping works though




回答2:


You have to call [tableView deselectRowAtIndexPath:indexPath animated:YES]; to fix this



来源:https://stackoverflow.com/questions/27906793/uitableview-didselectrowatindexpath-sometimes-called-after-second-tap

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!