Few.swift icon indicating copy to clipboard operation
Few.swift copied to clipboard

iOS: table view selection doesn't really work

Open Adlai-Holler opened this issue 9 years ago • 5 comments

@joshaber We call reloadData() every time we diff a TableView, and that kills our selection. I'll work on this one – just putting it here as a reminder.

Current thinking is we need to make Element equatable, and not call reloadData() unless our row data has actually changed. Thoughts?

Adlai-Holler avatar Jul 09 '15 16:07 Adlai-Holler

Good one

This seems hard to fix because if you want to make Element conform to Equatable you have to check all properties of Element and also all subclasses must overwrite the == func to add checks for their properties.

ghost avatar Jul 09 '15 17:07 ghost

Yeah, I'd really like to avoid making Element Equatable for those reasons :point_up:

joshaber avatar Jul 09 '15 17:07 joshaber

On Mac we save and restore the selected indexes: https://github.com/joshaber/Few.swift/blob/221ff4ccf6c339bb7d815398614556b07a80073d/Few-Mac/TableView.swift#L53-56 Could we do that on iOS too?

joshaber avatar Jul 09 '15 19:07 joshaber

@Adlai-Holler you can do something like this to preserve the selection:

            TableView([state.elements],
                selectedRow: state.selected,
                selectionChanged: { [unowned component] indexPath in
                    component.updateState { state in
                        var state = state
                        state.selected = indexPath
                        return state
                    }
                })
struct AppState {
    var elements: [Element]
    var selected: NSIndexPath?
}

To me it seems ok that elements do not have state. You can make component that wraps TableView element and adds state in this way. Otherwise leaving state management to native implementation of UITableView seems to me like leaky abstraction.

aocenas avatar Dec 11 '15 21:12 aocenas

Hi there!!! My name is Patrick and i'm begin in coding, i was hoping if it's possible if you can help me to understand how this github work, and what it does basically.

Rene759 avatar May 03 '16 11:05 Rene759