gpt4 book ai didi

iphone - 当点击另一个 UITextField 调出选择器时,键盘不会关闭

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:42:35 24 4
gpt4 key购买 nike

我有 2 个文本字段,单击时我正在处理每个文本字段,打开一个选择器轮,顶部有一个工具栏,可以选择关闭选择器并调出键盘一切正常,除非你关闭选择器并带上向上键盘然后单击下一个文本字段。我把键盘放在上面,后面是新的 pickerview。使键盘消失的唯一方法是在第一个文本字段中单击返回并单击完成或屏幕上的任何位置(不是文本字段)。

这是我的代码:

- (void)textFieldDidBeginEditing:(UITextField *)textField
{
for (NSUInteger i = 0; i<[self.fieldsArray count]; i++) {
if ([self.fieldsArray objectAtIndex:i] == textField) {
UITextField *input = [self.fieldsArray objectAtIndex:i];

if (input.tag == 3 && !self.overrideDriver) {
[self animatePickDriverForInput:input];
}
if (input.tag == 4 && !self.overrideVehicle) {
[self animatePickVehicleForInput:input];
}

}
}
}

下面是一些其他使用的方法:

- (IBAction)textFieldFinished:(id)sender
{
[sender resignFirstResponder];
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField {

[textField resignFirstResponder];

return YES;

}

- (void)animatePickDriverForInput:(UITextField *)input
{
if ([self.drivers count] > 0) {
[self.view endEditing:YES];
[self showPickDriver];
} else {
//untested
[input addTarget:self action:@selector(textFieldFinished:)
forControlEvents:UIControlEventEditingDidEndOnExit];
}
}


- (void)animatePickVehicleForInput:(UITextField *)input
{
if ([self.vehicles count] > 0) {
[self.view endEditing:YES];
[self showPickVehicle];
} else {
//untested
[input addTarget:self action:@selector(textFieldFinished:)
forControlEvents:UIControlEventEditingDidEndOnExit];
}
}

- (void)allowManualEntryOfDriver
{
[self.additionalButtonPickerHelper animateDismiss:self.pickDriver];
self.overrideDriver = YES;
[self.driver becomeFirstResponder];
}

- (void)allowManualEntryOfVehicle
{
[self.additionalButtonPickerHelper animateDismiss:self.pickVehicle];
self.overrideVehicle = YES;
[self.vehicle becomeFirstResponder];
}



- (void)showPickVehicle {
self.pickVehicle = [self.additionalButtonPickerHelper createPicker:self.pickVehicle WithTag:2 WithOtherButtonText:@"Add Other Vehicle"];
[self.additionalButtonPickerHelper showPicker:self.pickVehicle WithDoneAction:@selector(dismissVehiclePicker) OrWithOtherAction:@selector(allowManualEntryOfVehicle)];
}

- (void)showPickDriver {
self.pickDriver = [self.additionalButtonPickerHelper createPicker:self.pickDriver WithTag:1 WithOtherButtonText:@"Add Other Driver"];
[self.additionalButtonPickerHelper showPicker:self.pickDriver WithDoneAction:@selector(dismissDriverPicker) OrWithOtherAction:@selector(allowManualEntryOfDriver)];
}

编辑:

更多代码:

- (void)dismissDriverPicker
{
[self.additionalButtonPickerHelper animateDismiss:self.pickDriver];
}

- (void)dismissVehiclePicker
{
[self.additionalButtonPickerHelper animateDismiss:self.pickVehicle];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}

这可能不是最有效的方法,但我是 objective-c 的新手,正在寻找我能理解的解决方案。谢谢!

编辑这里是图片keyboard being stuck

最佳答案

您也可以尝试使用 textField 的属性:inputView

The custom input view to display when the text field becomes the first responder.

因此,您可以显示此 View 而不是键盘,并且不要手动处理它。

或者:

现在出现错误行为,因为还显示了第二个文本字段的键盘。所以你不仅要辞去first field的first responder,还要实现:

-(BOOL) textFieldShouldBeginEditing:(UITextField *)field {
return NO;
}

关于iphone - 当点击另一个 UITextField 调出选择器时,键盘不会关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16106047/

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