Reputation: 993
Based on my previous question in here . I have two datePicker
let say A and B. I want to set maximum of A is B.date and minimum of B is A.date.
But when i change the B value, the A maximum value still in old B maximum value. I dont have any idea about this.
let date = NSDate()
self.datePickerFrom.maximumDate = date as Date
self.datePickerTo.minimumDate = datePickerFrom.date
Any sugest and answer will helpfull for me. Thanks in Advance.
Upvotes: 0
Views: 591
Reputation: 89509
You need to tell some function in your view controller that the date pickers have changed. To do that, declare some @IBAction in your view controller that looks like this:
@IBAction func datePickerChanged(sender: UIDatePicker)
{
print("date has been set to \(sender.date)")
}
Then click on your date pickers in your storyboard or XIB file and connect the "Valued Changed" event to this new method.
Then try running it to see if the print
line prints in the console.
If it does, you can fill out more of that function. Perhaps something like this:
@IBAction func datePickerChanged(sender: UIDatePicker)
{
if sender == self.datePickerFrom
{
self.datePickerTo.minimumDate = sender.date
}
if sender == self.datePickerTo
{
self.datePickerFrom.maximumDate = sender.date
}
}
Upvotes: 2