LimitCellSelect
Intoduction
You can specify the maximum number of cells that can be selected, and specify the cells that are selected by default.
Requirements
LimitCellSelect
is written in Swift 3. Compatible with iOS 9.0+
Usage
import Library
import LimitCellSelect
initial Limit and default select index
To limit the number of cell selections and preselect a cell
limitCellSelect = LimitCellSelect.init(limit: 3, defaultIndex: [0,2])
or If you do not use defaultSelect
limitCellSelect = LimitCellSelect.init(limit: 3)
And when the cell is created, it is set by using the set () method.
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .default, reuseIdentifier: "reuseIdentifier")
// Setting limitCellSelect
limitCellSelect.set(cell: cell, row: indexPath.row)
return cell
}
To select a cell and return the selected cell, use the on () and selectCells () methods.
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
guard let cell = tableView.cellForRow(at: indexPath) else { return }
//Checks the currently selected cell.
limitCellSelect.on(cell: cell, row: indexPath.row)
//Returns the selected cells.
print(limitCellSelect.selectCells())
}
Installation
Cocoapods
LimitCellSelect is available through CocoaPods.
pod 'LimitCellSelect'
Carthage
LimitCellSelect is available through Carthage.
github "https://github.com/kaskay/LimitCellSelect"
Author
License
LimitCellSelect is available under the MIT license.