我将UIDatePicker
作为输入视图添加到UITextField
UIDatePicker *oBirth;
NSDateFormatter *dateFormat;
_editingField = [[UITextField alloc] initWithFrame : CGRectMake(80, 12, 215, 25)];
dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat : @"dd/MM/yyyy"];
oBirth = [[UIDatePicker alloc] initWithFrame : CGRectMake(0, 0, 120, 45)];
oBirth.date = [dateFormat dateFromString : sField];
NSLog(@"%@", oBirth.subviews);
[oBirth addTarget : self
action : @selector(updateDate:)
forControlEvents : UIControlEventValueChanged];
[oBirth addTarget : self
action : @selector(dismissDate:)
forControlEvents : UIControlEventTouchUpOutside];
[oBirth setDatePickerMode : UIDatePickerModeDate];
_editingField.tag = 1;
_editingField.inputView = oBirth;
如何在不创建隐形视图的情况下解除UIDatePicker
?
答案 0 :(得分:2)
试试这个
[_editingField resignFirstResponder];
修改强>
未调用dismissDate
。
删除这段代码
[oBirth addTarget : self
action : @selector(dismissDate:)
forControlEvents : UIControlEventTouchUpOutside];
并添加此
// single tap gesture recognizer
UITapGestureRecognizer *tapGestureRecognize = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissDate:)];
tapGestureRecognize.numberOfTapsRequired = 1;
[self.view addGestureRecognizer:tapGestureRecognize];
你的回调
- (void)dismissDate:(UIGestureRecognizer *)gestureRecognizer {
NSLog(@"Resign your responder");
}