I gave u the access to video. Please check it again.
That 3 users told me that their operaion system is IOS12.
Showing the complete code is difficult 'cos there is many abstractins and some part of logic is in the storyboards. I can try to show u the parts of it as much as possible.
// MARK: - UIPickerViewDelegate // UIPickerViewDataSource
extension MyTableViewController: UIPickerViewDelegate, UIPickerViewDataSource {
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return Date().year - Constants.startYear + 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return (Constants.startYear + row).description
}
func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {
datePickerWillReturn(row: row)
}
}
//delegate for "Done" button on toolbar
extension MyTableViewController: PickerViewAccessibleTableViewCellDelegate {
func didSelectDoneButton() {
datePickerWillReturn(row: pickerView.selectedRow(inComponent: 0))
}
}
private func datePickerWillReturn(row: Int) {
/* // this method is just setting selected row value into cell textfield
and it is called in two times - button "Done" and from picker delegate */
}
and there is the picker table view cell
protocol PickerViewTableViewCellDelegate: class {
func didSelectDoneButton()
}
class MyTableViewCell: UITableViewCell {
weak var delegate: PickerViewTableViewCellDelegate?
public func pickerView(_ view: UIView) {
let toolBar = UIToolbar()
toolBar.barStyle = .default
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(title: "Done".localized, style: .plain, target: self, action: #selector(didSelectDoneButton))
let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil)
toolBar.setItems([spaceButton, doneButton], animated: false)
toolBar.isUserInteractionEnabled = true
textField.inputAccessoryView = toolBar
view.frame.size.height = Constants.defaultKeyboardHeight
textField.inputView = view
}
public func presentPickerView() {
textField.becomeFirstResponder()
}
private var textField = UITextField(frame: CGRect(x: 0, y: 0, width: 1, height: 1))
@objc private func didSelectDoneButton() {
delegate?.didSelectDoneButton()
textField.resignFirstResponder()
}
override func awakeFromNib() {
super.awakeFromNib()
self.textField.isHidden = true
self.contentView.addSubview(self.textField)
}
}
PickerViewTableViewCellDelegate is setted in viewDidLoad of MyTableViewController and all delegates are setted.
And this code was checked by several other developers and they can't find the reason