AssistoLab / DropDown

A Material Design drop down for iOS
MIT License
2.44k stars 622 forks source link

Calling `selectRows(at index)` or `selectRows(at indices:)` does't trigger selectionAction closure #158

Open wongzigii opened 6 years ago

wongzigii commented 6 years ago
/// (Pre)selects a row at a certain index.
public func selectRow(at index: Index?) {
    if let index = index {
        tableView.selectRow(
            at: IndexPath(row: index, section: 0), animated: true, scrollPosition: .none
        )
        selectedRowIndices.insert(index)
    } else {
        deselectRows(at: selectedRowIndices)
        selectedRowIndices.removeAll()
    }
}

public func selectRows(at indices: Set<Index>?) {
    indices?.forEach {
        selectRow(at: $0)
    }

    // if we are in multi selection mode then reload data so that all selections are shown
    if multiSelectionAction != nil {
        tableView.reloadData()
    }
}

Why don't these two methods trigger the selectionAction closure?

TopeMateo commented 6 years ago

I'm having the same issue, calling the selectRow doesn't trigger the selectionAction, are we missing somethig???

TopeMateo commented 6 years ago

@wongzigii I found the solution to our problems here, https://github.com/AssistoLab/DropDown/issues/84

Turns out, we should call the DropDownObject.selectionAction?(index, value), where index is the pointer of the item you want to select and value is the actual value of the item. Hope this helps!

wongzigii commented 6 years ago

@TopeMateo Thanks for your info!