gpt4 book ai didi

ios - 从 inputView 获取 UItextField

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:06:56 25 4
gpt4 key购买 nike

我有 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);
}

有没有办法在 updateTextField 方法中获取 UITextField

最佳答案

是的,您可以像这样获取对 textView 的引用:

-(void)updateTextField:(id)sender
{
UIDatePicker *datePicker = (UIDatePicker*) sender;
UITextField *dateField = (UITextField*)datePicker.inputView;
}

//扩展

抱歉我的错误,我认为您将文本字段作为输入 View 添加到数据选择器。另一种你可以做你想做的事情的方法是将标签分配给你设置它的 TextView :

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

在您的方法 updateTextField 中:您可以像这样访问它:

UITextField *dateField = (UITextField*)[self viewWithTag:10];

关于ios - 从 inputView 获取 UItextField,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21331714/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com