0

I have several UITextfields in one of my app's Viewcontroller. It works fine and I can type letters on those textfields. But sometimes cursor appears on the UITextfield but cannot type any letter on that. This does not happen always. What I do is when this problem occurs I delete that particular UITextfield and re-add a new UITextfield. But after performing several functionalities again that also gets the same problem.

What is the reason for this? And how to solve this problem. Please please help me. I'm fighting with this for several days. Those are in Editable and User interactions are already enabled for these.

These are the delegates which I used

-(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;
 }

}
11
  • 3
    First put code of creation of UITextField..
    – iPatel
    Nov 28, 2013 at 6:56
  • I just added as outlets. I didnt create them programmatically Nov 28, 2013 at 6:56
  • Do you implement any of the delegate methods for UITextField ?
    – giorashc
    Nov 28, 2013 at 6:57
  • check your connections in the xib are correct
    – manujmv
    Nov 28, 2013 at 6:58
  • For the keyboard return key I have implemented to dissmiss that Nov 28, 2013 at 6:58

1 Answer 1

3

Can't say without looking at implementation, but it may be due to your code in some of UITextField delegate methods especially -

  1. if you return NO in – textFieldShouldBeginEditing: or

  2. did something in wrong textField:shouldChangeCharactersInRange:replacementString

7
  • Please post – textFieldShouldBeginEditing: and textField:shouldChangeCharactersInRange:replacementString methods.
    – Atul
    Nov 28, 2013 at 7:07
  • I havent Implemented textfieldshouldbegingediting only didbeginediting I will update the characters in range method Nov 28, 2013 at 7:11
  • But this range method has not any deal with this particular textboxes Nov 28, 2013 at 7:15
  • Please check if you have set textField delegate correctly and this method is not getting called for these textFields.
    – Atul
    Nov 28, 2013 at 7:18
  • What should I imlement in textFieldShouldBeginEditing method? Nov 28, 2013 at 7:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.