我在我的应用程序 Viewcontroller
之一中有了一个_1143937_ . 它工作正常,我可以在这些文本字段上键入字母 . 但有时光标出现在 UITextfield
但不能在其上键入任何字母 . 这不会永远发生 . 我所做的是当这个问题发生时我删除那个特定的 UITextfield
并重新添加一个新的 UITextfield
. 但在再次执行几个功能后,也会遇到同样的问题 .
这是什么原因 . 以及如何解决这个问题 . 请帮帮我 . 几天以来我一直在与此斗争 . 这些是可编辑的,并且用户交互已经为这些启用了 .
这些是我使用的代表
`
-(void)textFieldDidBeginEditing:(UITextField *)textField {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
if ([UIScreen mainScreen].bounds.size.height==480) {
if (textField.tag==7) {
CGPoint npoint=originalCenter;
npoint.y=180;
self.view.center=npoint;
}
else if (textField.tag==8)
{
CGPoint npoint=originalCenter;
npoint.y=125;
self.view.center=npoint;
}
else{
self.view.center=originalCenter;
}
}
else{
if (textField.tag==8)
{
CGPoint npoint=originalCenter;
npoint.y=250;
self.view.center=npoint;
}
else{
self.view.center=originalCenter;
}
}
[UIView commitAnimations];
}
`
`
- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.view.center=originalCenter;
[UIView commitAnimations];
[textField resignFirstResponder];
return NO;
}
`
` - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
if ([textField isEqual:txtPhonenumber]) {
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return (newLength > 9) ? NO : YES;
}
else if ([textField isEqual:txtVerification])
{
NSUInteger newLength = [textField.text length] + [string length] - range.length;
return (newLength > 4) ? NO : YES;
}
}
1 回答
不能不看实现,但可能是由于你的代码在某些textField委托方法中特别 -
如果您在 - textFieldShouldBeginEditing: 或_中返回NO
在错误的textField中执行了某些操作: shouldChangeCharactersInRange:replacementString