我有两个文本字段,fromdate 和 todate。如何从同一个 datepicker 获取不同的日期。我尝试了一些方法,当日期更改时,最终在两个文本字段中获得了相同的日期。
-(IBAction)dateValueChanged:(id)sender
{
UIDatePicker *picker = (UIDatePicker *)sender;
NSDate *dateSelected1 = [picker date];
NSDate *dateSelected2 = [picker date];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"dd-MM-yyyy"];
self.fromTextField.text = [dateFormatter stringFromDate:dateSelected1];
self.toTextField.text = [dateFormatter stringFromDate:dateSelected2];
}