Search code examples
ioscursortextinput

iOS6 Putting Cursor in SPecific Text Field


I have three text input fields that I clear after the user has added data to a database:

 self.textMonth.text  = @"";
 self.textTemp.text   = @"";
 self.textCloud.text  = @"";

How to I put the cursor in any one of those fields subsequently?

I have tried a number of the solutions provided elsewhere but none seem to work. Many thanks. EH


Solution

  • just make your text field first responder using becomeFirstResponder like....

     [self.textMonth becomeFirstResponder];
    

    to change textfield subsequently use textFieldShouldReturn

    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
        if([self.textMonth isFirstReponder])
        {
            [self.textTemp becomeFirstResponder];
        }
        else if([self.textTemp isFirstReponder])
        {
            [self. textCloud becomeFirstResponder];
        }
        else if([self.textCloud isFirstReponder])
        {
            [self.textMonth becomeFirstResponder];
        }
        return YES;
    }
    

    Hope it will help to solve your problem