PickerViewCell
PickerViewCell copied to clipboard
A Swift5 library implement the UITableViewCell with a UIDatePicker or a UIPickerView.
PickerViewCell
We provide two types of UITableViewCell:
1. DatePickerTableViewCell: when you make this cell `becomeFirstResponder`, it will invoke a UIDatePicker and then you can use the delegate function to get the value of the picker.
2. PickerTableViewCell: when you make this cell `becomeFirstResponder`, it will invoke a UIPickerView. You should specify your datasource and delegate.
Demo
Installation
pod 'PickerViewCell'
Useage
Make your table view cell be the cells we provided, and just invoke becomeFirstResponder
when the cell is selected.
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.deselectRow(at: indexPath, animated: true)
if let cell = tableView.cellForRow(at: indexPath) as? DatePickerTableViewCell {
cell.delegate = self
if !cell.isFirstResponder {
_ = cell.becomeFirstResponder()
}
} else if let cell = tableView.cellForRow(at: indexPath) as? PickerTableViewCell {
cell.delegate = self
cell.dataSource = self
if !cell.isFirstResponder {
_ = cell.becomeFirstResponder()
}
}
}