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

How to sync the state to tableView from Cell? #219

Open
mozartee opened this issue Oct 7, 2023 · 1 comment
Open

How to sync the state to tableView from Cell? #219

mozartee opened this issue Oct 7, 2023 · 1 comment

Comments

@mozartee
Copy link

mozartee commented Oct 7, 2023

Thanks for making the lib, but I want to know How can I sync the data state with controller and cell.
For example, I have a button in the cell, and I need to toggle the selected state with the button,
what should I do?

@sanghun0724
Copy link
Contributor

sanghun0724 commented Oct 30, 2023

What about this?
(if tableView Section is only one)

  1. you can make Dictionary<IndexPath.row, Bool> in State Struct
    e.g)
struct State {
    var isSelectedToggls: [Int: Bool] = [:]
}
  1. make action from your tableView cell tap with cell Index
enum Action {
    case cellDidTapped(Int)
}
  1. and then you can update Dictionary State -(1) using mutation in your Reactor

  2. When the state changes, you can reload table or bind tableView

I hope it helps @mozartee

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