0

i have registration page with text fields like user name,first name,password.when user clicks on submit button.if any field is empty i want to place the cursor position that text field,can any one help me out.

1
  • textField becomeFirstResponder;
    – Kumar KL
    Nov 13, 2013 at 7:25

2 Answers 2

2

You can try this, It will look for any empty field in the parent view, and will assign focus to it

for(UIView* subView in [self.yourView subviews])
 {
    if([subView isKindOfClass:[UITextField class]])
    {
        UITextField* textFeild = (UITextField*) subView;
        if([textFeild.text isEqualToString:@""])
        {

           [textFeild becomeFirstResponder];   ///Assign Focus
            break;
        }
    }
}

Hope it helps

1
  • this helped me @sarim sidd
    – ShujatAli
    Nov 13, 2013 at 8:18
2

Find your text field object. And place this in your code.

if(textfieldobj.text.length == 0)
{
   [textfieldobj becomeFirstResponder];
}

Hope this may help you...

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.