UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

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!

3      

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

3      

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

3      

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

3      

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

3      

@twostraws  Site AdminHWS+

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

3      

Happened to me at least twice, no worries.

3      

BUILD THE ULTIMATE PORTFOLIO APP Most Swift tutorials help you solve one specific problem, but in my Ultimate Portfolio App series I show you how to get all the best practices into a single app: architecture, testing, performance, accessibility, localization, project organization, and so much more, all while building a SwiftUI app that works on iOS, macOS and watchOS.

Get it on Hacking with Swift+

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

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

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.