NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

SOLVED: Question: DidSelectRowAt acting a bit wierd

Forums > 100 Days of Swift

Hi guys, I am experiencing a bit of an odd behaviour while im trying to complete Milestone Challenge 13-15. I'm trying to do a simple detail push view but I m not getting it right. Instead I get this behaviour: I select a cell from the tableView, the cell stays selected then I have to select another cell for the frisr cell related detail view to come up. Here's my did select function:

override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) { if let vc = storyboard?.instantiateViewController(withIdentifier: "Detail") as? DetailViewController { vc.facts = countries[indexPath.row] navigationController?.pushViewController(vc, animated: true) }

}

Thanks!

   

Hi, this is standard TableView behaviour. You can use the deselectRow method to deselect user selection after the push.

   

Hi, Thanks for the reply. I tried calling the deselectRowAt method of the tableView but I'm experiencing the same issue. :(

override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
        if let vc = storyboard?.instantiateViewController(withIdentifier: "Detail") as? DetailViewController {
            vc.facts = countries[indexPath.row]
            navigationController?.pushViewController(vc, animated: true)
        }
        tableView.deselectRow(at: indexPath, animated: true)

    }

EDIT: I linked a video of how it manifests, hope is not against the rules. https://streamable.com/ezh6tn

   

Looks like you have different delegate method than you want. For user selection you should use didSelectRowAt, you have didDEselectRowAt :-)

1      

Oh dear, I should see an eye doctor. Thanks mate! I feel really silly now.

   

@twostraws  Site AdminHWS+

Nothing to feel silly about – this is a remarkably common and easy mistake to make 🙂

   

Happened to me at least twice, no worries.

   

Hacking with Swift is sponsored by RevenueCat

SPONSORED Building and maintaining in-app subscription infrastructure is hard. Luckily there's a better way. With RevenueCat, you can implement subscriptions for your app in hours, not months, so you can get back to building your app.

Try it for free

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.