3

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非表示のビューを作成せずに を閉じるにはどうすればよいですか?

4

1 に答える 1

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");
}
于 2012-12-13T09:21:44.113 に答える