I am able to select date succefully using simple textfield ,but in case of textfield within tableview cell,i am facing problem and not able to select date.As far as i am able to identfy my action method donePressed is not working properly as i am able to print date using dateformatter in console on selecting date.but i am unable to figure out how to print that date inside the textfield present in the cell.
let datePicker = UIDatePicker()
override func viewDidLoad() {
super.viewDidLoad()
tableView.reloadData()
donePressed()
//createDatePicker()
// Do any additional setup after loading the view.
}
//Private function
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
let toolBar = UIToolbar()
toolBar.sizeToFit()
let doneBtn = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
cell.dateText.inputAccessoryView = toolBar
cell.dateText.inputView = datePicker
cell.dateText.text = "\(datePicker.date)"
toolBar.setItems([doneBtn], animated: true)
return cell
}
@objc func donePressed() {
let cell1 = tableView.dequeueReusableCell(withIdentifier: "cell") as! TableViewCell
cell1.dateText.text = "\(datePicker.date)"
self.view.endEditing(true)
}
/* func createDatePicker()
{
let toolBar = UIToolbar()
toolBar.sizeToFit()
let doneBtn = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(donePressed))
dateText.inputAccessoryView = toolBar
dateText.inputView = datePicker
toolBar.setItems([doneBtn], animated: true)
}*/