textFieldShouldBeginEditing 仅在 iPad 中被重复调用
textFieldShouldBeginEditing is called repeatedly only in iPad
我有两个文本字段(名称和 phone#)。用户注册后,用户将无法编辑 phone 数字文本字段。当用户单击 phone 数字文本字段时,我正在检查条件。如果已注册,我将创建警告说 "Cannot edit"。当我点击 "ok" 时,我关闭了键盘。我正在使用以下代码来做到这一点
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(registered)
{
dismissAlert = [[UIAlertView alloc]initWithTitle:@"cannot edit" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[dismissAlert show];
}
}
if([title isEqualToString:@"OK"])
{
[self.view endEditing:YES];
[self.PhoneNumber resignFirstResponder];
dismissAlert = nil;
}
但是多次调用了 textFieldShouldBeginEditing。它只发生在 iPad.
试试这个 -
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == txtPhone)
{
[self performSelector:@selector(phoneAlert) withObject:nil afterDelay:0.1];
return NO;
}
return YES;
}
-(void)phoneAlert
{
dismissAlert = [[UIAlertView alloc]initWithTitle:@"cannot edit" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[dismissAlert show];
}
终于,我明白了。我设置
self.PhoneNumber.userInteractionEnabled = NO;
我有两个文本字段(名称和 phone#)。用户注册后,用户将无法编辑 phone 数字文本字段。当用户单击 phone 数字文本字段时,我正在检查条件。如果已注册,我将创建警告说 "Cannot edit"。当我点击 "ok" 时,我关闭了键盘。我正在使用以下代码来做到这一点
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(registered)
{
dismissAlert = [[UIAlertView alloc]initWithTitle:@"cannot edit" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[dismissAlert show];
}
}
if([title isEqualToString:@"OK"])
{
[self.view endEditing:YES];
[self.PhoneNumber resignFirstResponder];
dismissAlert = nil;
}
但是多次调用了 textFieldShouldBeginEditing。它只发生在 iPad.
试试这个 -
-(BOOL)textFieldShouldBeginEditing:(UITextField *)textField
{
if(textField == txtPhone)
{
[self performSelector:@selector(phoneAlert) withObject:nil afterDelay:0.1];
return NO;
}
return YES;
}
-(void)phoneAlert
{
dismissAlert = [[UIAlertView alloc]initWithTitle:@"cannot edit" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
[dismissAlert show];
}
终于,我明白了。我设置
self.PhoneNumber.userInteractionEnabled = NO;