与文本字段和dateselect器相关的问题

我有一个隐藏问题,并显示datepicker视图时,单击文本字段…其实我有2个textfields ..这是我的问题形象…

问题

datepicker显示和隐藏,当点击textfiled …它应该显示开始编辑和隐藏在结束编辑…

在这里输入图像说明

当我们第一次点击“textfield 1”时它的工作良好,但是一旦它resignFirstResponder并且使第二个字段响应,就会出现问题。

 func textFieldShouldBeginEditing(textField: UITextField) -> Bool { self.datepicker.alpha = 0.0 self.datepicker.hidden = false UIView.animateWithDuration(0.3, animations: { () -> Void in self.datepicker.alpha = 1.0 self.conDateHeight.constant = 100.0 self.datepicker.addTarget(self, action: Selector("dataPickerChanged:"), forControlEvents: UIControlEvents.ValueChanged) }) return true } func textFieldShouldEndEditing(textField: UITextField) -> Bool { UIView.animateWithDuration(0.3, animations: { self.datepicker.alpha = 0.0 }, completion: { (value: Bool) in self.conDateHeight.constant = 0.0 self.datepicker.hidden = true }) return true } func textFieldShouldReturn(textField: UITextField) -> Bool { if textField == self.txtToDate { txtToDate.resignFirstResponder() txtFromDate.becomeFirstResponder() } else if textField == self.txtFromDate { txtFromDate.resignFirstResponder() txtToDate.becomeFirstResponder() } return true } 

当我在第一个文本框之后隐藏键盘,然后在第二个文本框中input它的确定…否则问题就是这样

面糊使用dateselect器作为input视图

 UIView *viewDateInput = [[UIView alloc] initWithFrame:CGRectMake(0, 0,[UIScreen mainScreen].bounds.size.width, 200)]; [viewDateInput setBackgroundColor:[UIColor whiteColor]]; self.pickerDate = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, viewDateInput.frame.size.width, viewDateInput.frame.size.height)]; self.pickerDate.datePickerMode = UIDatePickerModeDate; [viewDateInput addSubview:self.pickerDate]; [self.pickerDate addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged]; [self.txtDate setInputView:viewDateInput]; 

function对于date更改

 - (void)dateChanged:(id)sender { NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setDateFormat:@"yyyy-MM-dd"]; NSString *currentTime = [dateFormatter stringFromDate:self.pickerDate.date]; self.txtDate.text = currentTime; }