-1

I have a table view populated with a list of files from a directory. In the following code the first click on the table returns nothing. The second click returns the label for the first cell the third click returns the label for the second click etc.

override func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) {
    selectedRow = indexPath.row

    let cell = self.tableView.cellForRowAtIndexPath(indexPath)
    if cell != nil {
        selectedFile = cell!.textLabel!.text
        println("selected File \(selectedFile)")
        var refreshAlert = UIAlertController(title: "Refresh", message: "Selected file \(selectedFile)", preferredStyle: UIAlertControllerStyle.Alert)
        refreshAlert.addAction(UIAlertAction(title: "Ok", style: .Default, handler: { (action: UIAlertAction!) in
            println("Handle Ok logic here") }))


        presentViewController(refreshAlert, animated: true, completion: nil)

    }

   println("did select and the text is \(cell?.textLabel?.text)")
Vladimir
  • 170,431
  • 36
  • 387
  • 313
  • possible duplicate of [UITableView didSelectRowAtIndexPath: not being called on first tap](http://stackoverflow.com/questions/2106292/uitableview-didselectrowatindexpath-not-being-called-on-first-tap) – Martin R Mar 23 '15 at 14:39
  • Does your paragraph at the top describe *desired* behavior or *actual* incorrect behavior? In either case, please provide the other behavior as well. – Oblivious Sage Mar 23 '15 at 14:39

1 Answers1

2

You mistyped parameter name in the method method - you used didDeselectRowAtIndexPath instead of didSelectRowAtIndexPath. Should be

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath)
Vladimir
  • 170,431
  • 36
  • 387
  • 313