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

Deselecting table view cell automatically after selection #126

Closed
csr opened this issue Dec 13, 2018 · 4 comments
Closed

Deselecting table view cell automatically after selection #126

csr opened this issue Dec 13, 2018 · 4 comments

Comments

@csr
Copy link

csr commented Dec 13, 2018

How would I go about deselecting a table view cell? I'm currently using

let cellStyle = CellStyle(bottomSeparator: .inset,
                          separatorColor: .gray,
                          highlight: true,
                          selectionColor: UIColor(named: "selectedCell"),
                          backgroundColor: .black)

This code highlights the cell on tap but then the cell never gets deselected afterwards. I took a look at the CellStyle docs but couldn't find a propriety that handles deselection. I'm aware there are CellActions I can use (specifically the deselectionAction), although the action returns an item/index so not sure if I can use that.

How would I go about having functional table data deselect my cell automatically? Thanks :)

screenshot

@raulriera
Copy link
Contributor

Hey,

public typealias SelectionAction = (_ sender: UIView) -> SelectionState
public typealias DeselectionAction = (_ sender: UIView) -> SelectionState

These two actions asks you to return the selection state, returning .deselected will not leave it in that state. If you want to mimic what UITableViewController does, and automatically unselect any cell when you dismiss another view controller. Then you will need to get your hands dirty a bit

@csr
Copy link
Author

csr commented Dec 13, 2018

Got it, thanks. I think I'll need to forgo the selection thing for now unless you may have some pointers on how I could implement it/contribute to make it happen somehow.

@csr csr closed this as completed Dec 13, 2018
@raulriera
Copy link
Contributor

Depends on what you are trying to do. Are you trying to do automatic deselection? You can always query all selected index paths and deselect them by accessing your tableView directly

@csr
Copy link
Author

csr commented Dec 13, 2018

That works great thanks :)

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

No branches or pull requests

2 participants