当用户选择UITextField
. 我目前有三个文本字段:两个UIPickerView
(由同一个选择器控制)和一个文本输入字段。当我单击“返回”或在后台单击时,键盘通过resignFirstResponder
呼叫消失。
问题:
当我当前正在编辑文本输入字段然后立即选择UITextField
w/UIPickerView
功能时,键盘不会消失。我觉得我已经尝试了所有解决方案,并且正在用头撞墙......
代码:
-(void)textFieldDidBeginEditing:(UITextField *)textField{
[pickerView setHidden:YES];
if (fldQuiver.editing == YES) {
[fldTitle resignFirstResponder];
[fldQuiver resignFirstResponder];
[pickerView setHidden:NO];
variabla = 1;
}else if (fldCategory.editing == YES) {
[fldTitle resignFirstResponder];
[fldCategory resignFirstResponder];
[pickerView setHidden:NO];
variabla = 2;
}
NSLog(@"variabla %d",variabla);
[pickerView reloadAllComponents];
}
任何帮助,将不胜感激。提前致谢。
编辑的王子代码:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField; // return NO to disallow editing.
{
//set logic for picker view here
if (textField == fldQuiver)
{
variabla = 1;
}
else if (textField == fldCategory) {
variabla = 2;
}
else
{
}
NSLog(@"variabla %d",variabla);
[pickerView reloadAllComponents];
if (textField == fldQuiver)
{
[fldTitle resignFirstResponder];
[pickerView setHidden:NO];
return NO;
}
else if (textField == fldCategory) {
[fldTitle resignFirstResponder];
[pickerView setHidden:NO];
return NO;
}
else
{
[pickerView setHidden:YES];
return YES;
}
}
另外:我已经“合成”并声明了@property
fldQuiver
and fldCategory
。我有IBOutlet
, fldTitle
, fldQuiver
.fldCategory
pickerView
加载了一个基于变量的数组。