dei*_*mus 0 iphone uitextfield ipad ios
已经是第二天,无法弄清楚问题,
我UITabelView使用Custom UICellViews,每个自定义UICellView包含UILabel和UITextField.
自定义UICellView对象在其方法中分配UITextField并UILabel在其中init发布dealloc.
定制的数量UICellViews在UITableView6.
用户场景如下
UITextFields虚拟键盘时,用户会输入一些文字UITextField虚拟键盘处于活动状态时,它应该被隐藏,如果它被隐藏,它将不会被显示.作为UITextFieldDelegate我的UIViewController类中的实现协议,并将每个的委托设置UITextField为self.
我的委托方法如下
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.tag != 6) {
return YES;
} else {
[textField resignFirstResponder];
return NO;
}
}
-(BOOL) textFieldShouldEndEditing:(UITextField *)textField {
[textField resignFirstResponder];
return YES;
}
-(void) textFieldDidBeginEditing:(UITextField *)textField {
/* Some code */
}
-(void) textFieldDidEndEditing:(UITextField *)textField
{
[textField resignFirstResponder];
}
Run Code Online (Sandbox Code Playgroud)
所有功能都正常!
那么现在,虚拟键盘永远不会被隐藏,为什么会这样呢?
PS.类似的代码已在iPhone上运行,但这个问题存在于iPad上.
您需要知道上次使用的是哪个文本字段!所以你可以做到[lastUsedTextField resignFirstResponder]
有一个肮脏但有效的技巧..你可以使你的textfield成为新的活动UITextField并立即在下一个周期中调用resignFirstResponder:
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if (textField.tag != 6) {
return YES;
} else {
// this will schedule keyboard dismissal for the current text field
dispatch_async(dispatch_get_main_queue(), ^{
[textField resignFirstResponder];
});
return YES; // -> make this one active
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1183 次 |
| 最近记录: |