From 804f01cc492524f581d02045d6f6c3f0535a6bc5 Mon Sep 17 00:00:00 2001 From: Ganesh Manickam Date: Fri, 8 Dec 2017 16:21:35 +0530 Subject: [PATCH] getting last clicked index in Multi select In multiSelectionAction return an addidtional parameter to identify last clicked index position --- Demo/ViewController.swift | 4 ++-- DropDown/src/DropDown.swift | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Demo/ViewController.swift b/Demo/ViewController.swift index f9ec1e63..09d1ea10 100644 --- a/Demo/ViewController.swift +++ b/Demo/ViewController.swift @@ -178,8 +178,8 @@ class ViewController: UIViewController { self?.chooseArticleButton.setTitle(item, for: .normal) } - chooseArticleDropDown.multiSelectionAction = { [weak self] (indices, items) in - print("Muti selection action called with: \(items)") + chooseArticleDropDown.multiSelectionAction = { [weak self] (lastClickedIndex,indices, items) in + print("Muti selection action called with: \(items) & last clicked index : \(lastClickedIndex)") if items.isEmpty { self?.chooseArticleButton.setTitle("", for: .normal) } diff --git a/DropDown/src/DropDown.swift b/DropDown/src/DropDown.swift index a1b6b39e..e031990f 100644 --- a/DropDown/src/DropDown.swift +++ b/DropDown/src/DropDown.swift @@ -11,7 +11,7 @@ import UIKit public typealias Index = Int public typealias Closure = () -> Void public typealias SelectionClosure = (Index, String) -> Void -public typealias MultiSelectionClosure = ([Index], [String]) -> Void +public typealias MultiSelectionClosure = (Int,[Index], [String]) -> Void public typealias ConfigurationClosure = (Index, String) -> String public typealias CellConfigurationClosure = (Index, String, DropDownCell) -> Void private typealias ComputeLayoutTuple = (x: CGFloat, y: CGFloat, width: CGFloat, offscreenHeight: CGFloat) @@ -1038,7 +1038,7 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate { let selectedRowIndicesArray = Array(selectedRowIndices) let selectedRows = selectedRowIndicesArray.map { dataSource[$0] } - multiSelectionCallback(selectedRowIndicesArray, selectedRows) + multiSelectionCallback(selectedRowIndex,selectedRowIndicesArray, selectedRows) return } else { @@ -1048,7 +1048,7 @@ extension DropDown: UITableViewDataSource, UITableViewDelegate { let selectedRows = selectedRowIndicesArray.map { dataSource[$0] } selectionAction?(selectedRowIndex, dataSource[selectedRowIndex]) - multiSelectionCallback(selectedRowIndicesArray, selectedRows) + multiSelectionCallback(selectedRowIndex,selectedRowIndicesArray, selectedRows) tableView.reloadData() return }