Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smarter table view row deselection #405

Closed
ZevEisenberg opened this issue May 5, 2016 · 4 comments
Closed

Smarter table view row deselection #405

ZevEisenberg opened this issue May 5, 2016 · 4 comments

Comments

@ZevEisenberg
Copy link
Contributor

Before submitting issues ...

The code in question is here, in FormViewController from Core.swift. I'm looking at the version on master at the time of this writing, which is from commit 826d8d9

public override func viewWillAppear(animated: Bool) {
    super.viewWillAppear(animated)
    if let selectedIndexPath = tableView?.indexPathForSelectedRow {
        tableView?.reloadRowsAtIndexPaths([selectedIndexPath], withRowAnimation: .None)
        tableView?.selectRowAtIndexPath(selectedIndexPath, animated: false, scrollPosition: .None)
        tableView?.deselectRowAtIndexPath(selectedIndexPath, animated: true)
    }
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(FormViewController.keyboardWillShow(_:)), name: UIKeyboardWillShowNotification, object: nil)
    NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(FormViewController.keyboardWillHide(_:)), name: UIKeyboardWillHideNotification, object: nil)
}

The problem with this is that if you use an interactive transition to start dismissing the pushed view (so that self is reappearing), and then change your mind and cancel the dismissal, the row is still deselected, a subsequent "Back" navigation doesn't show the row deselecting again.

The solution is to use the trick that I outline here: https://gist.github.com/ZevEisenberg/8951478e8c6907bd5e5a

The idea is that you use the transition coordinator to find out if the animation was canceled, and if it was, it reselects the desired rows so that they will still be selected on subsequent dismissal attempts.

@ZevEisenberg
Copy link
Contributor Author

ZevEisenberg commented May 5, 2016

My gist also assumes that you're being dismissed in a navigation controller, which may not be the case always.

@mtnbarreto
Copy link
Member

@ZevEisenberg Thanks for reporting the issue and provide info to solve it. It seems related with #402. I will look into it and get back to you shortly.

@mtnbarreto
Copy link
Member

mtnbarreto commented May 6, 2016

I have not tested this in a simulator neither in a real device but it seems to me it should work for any transition even custom transitions. Why did you say "My gist also assumes that you're being dismissed in a navigation controller" ?

@ZevEisenberg
Copy link
Contributor Author

@mtnbarreto in the original gist that I linked to, the function takes a navigation controller. When I submitted my PR, I tried using parentViewController, and that seemed to work in my nav controller test, but I haven't tried it with modal presentation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants