我有UITextField。我将UIDatePicker设置为此UITextField的inputView

UITextField *dateField = [[UITextField alloc] init];
        dateField.frame = CGRectMake(30, 180, 260, 30);
        dateField.delegate = self;
        [self addSubview:dateField];

        UIDatePicker *datePicker = [[UIDatePicker alloc]init];
        [datePicker setDate:[NSDate date]];
        datePicker.frame = CGRectMake(0, 568 - 100, 320, 100);
        [datePicker addTarget:self action:@selector(updateTextField:) forControlEvents:UIControlEventValueChanged];
        [dateField setInputView:datePicker];

-(void)updateTextField:(id)sender
{
    NSLog(@"SENDER = %@", sender);
}

有什么办法可以在UITextField方法中获取updateTextField

最佳答案

添加它并创建ivar currentTextField

- (void)textFieldDidBeginEditing:(UITextField *)textField {


     currentTextField = textField;


}

updateTextField中的currentTextField将是您的文本字段

09-25 20:11