0

UIDatePicker components not scrolling properly and sometimes moves outside of the view.

Tried with adding date picker programatically as well as using storyboards.

I am assigning date picker as textField's input view. And textField is in table view cell. Code

func assignDatePickerTo(textField: UITextField) { 
    let datePicker = UIDatePicker() 
    datePicker.datePickerMode = UIDatePickerMode.date 
    let currentDate = Date() 
    datePicker.minimumDate = currentDate      
    datePicker.setDate(currentDate, animated: false) 
    datePicker.backgroundColor = UIColor.white     
     datePicker.addTarget(self, action: #selector(self.neededFromDateChanged(sender:)), for: UIControlEvents.valueChanged) 

    textField.inputView = datePicker 
}

UI Screenshot below

enter image description here

  • It seems to be working properly. – dahiya_boy Jan 20 '17 at 11:38
  • Can you try this same by taking new datePicker after deleting this one. – dahiya_boy Jan 20 '17 at 11:43
  • @the_dahiya_boy Please see the attached screenshot the year component is showing in the middle and starts with 1 even if I set minimum date – Minal Jadhav Jan 20 '17 at 11:44
  • Can you share the relevant code of how you instantiated it? – Emptyless Jan 20 '17 at 11:46
  • @the_dahiya_boy Tried it. Actually i'm assigning the the date picker as textfield's input view – Minal Jadhav Jan 20 '17 at 11:47
  • Mail me your project – dahiya_boy Jan 20 '17 at 11:49
  • Here is code: func assignDatePickerTo(textField: UITextField) { let datePicker = UIDatePicker() datePicker.datePickerMode = UIDatePickerMode.date let currentDate = Date() datePicker.minimumDate = currentDate datePicker.setDate(currentDate, animated: false) formatAndShowDate(date: currentDate, textField: textField) datePicker.backgroundColor = UIColor.white datePicker.addTarget(self, action: #selector(self.neededFromDateChanged(sender:)), for: UIControlEvents.valueChanged) textField.inputView = datePicker } – Minal Jadhav Jan 20 '17 at 11:49
  • 1
    You should edit the question, adding that code to it. Comments can be easily deleted. – CPHPython Jan 20 '17 at 12:17
  • @CPHPython Edited question with code – Minal Jadhav Jan 20 '17 at 12:58

1 Answers1

0

The problem was due to some other third party library in which they have written the category on scrollView to updateContentSize when scrollView updates constraints which is getting called when I scroll datePicker.