Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6891937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T06:28:20+00:00 2026-05-27T06:28:20+00:00

I have 10 textfields, each of which could hold at most one character. When

  • 0

I have 10 textfields, each of which could hold at most one character. When I enter a character in the first textfield, the focus should automatically move to the next textfield and so on. That is, as soon as the first character is entered in a textfield, the focus should shift to the next. That is, the next textfield should become the first responder. I have written the below code, used the textfield delegate method.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {

NSCharacterSet *myCharSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"];

for (int i = 0; i < [string length]; i++) {
    unichar c = [string characterAtIndex:i];
    if([myCharSet characterIsMember:c])
    {
        int previousTag = textField.tag;


        if([textField.text length] > 0)
        {
            if((previousTag == 9) && ([textField10.text length] >0))
            {
                return NO;
            }
            UITextField *tempField=(UITextField *)[self.view viewWithTag:previousTag+1]; 
            if([tempField.text length] > 0){
                [tempField resignFirstResponder];
                return NO;
            }
            [tempField becomeFirstResponder];
            return YES;
        }

    }
    else{
        return NO;
    }
}


return YES;
}

But I am not getting the desired results. When I type a character its entered in the first textfield, but the focus is not shifting to the next, though when I type the 2nd character, it is entered in the next textfield.

Similarly, I need to write a delete function such that when I delete a textfield, the focus automatically shifts to the previous textfield.

Any answers will be appreciated. Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T06:28:21+00:00Added an answer on May 27, 2026 at 6:28 am

    You can always return NO and change the textField text manually. I guess what you need is something like this.

     - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    
    NSCharacterSet *myCharSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"];
    int previousTag = textField.tag;
    
    if ([string isEqualToString:@""]) {//backspace button
        if (previousTag==0) {//added to prevent crashing in first tf
            return YES;
        }
      UITextField *tempField2=(UITextField *)[self.view viewWithTag:previousTag-1]; 
    
        textField.text=string;
        [tempField2 becomeFirstResponder];
        return NO;
    
    }
    for (int i = 0; i < [string length]; i++) {
        unichar c = [string characterAtIndex:i];
        if([myCharSet characterIsMember:c])
        {
            if((previousTag == 9) && ([textField10.text length] >0))
            {
                return NO;
            }
    
            UITextField *tempField=(UITextField *)[self.view viewWithTag:previousTag+1]; 
            if([tempField.text length] > 0)
            { 
                textField.text=string;
                [tempField resignFirstResponder];
                return NO;
            }
            textField.text=string;
            [tempField becomeFirstResponder];
            return NO;
    
        }
        else{
            return NO;
        }
    
    
    }
    
    
    return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 10 textfields, in which I could enter only one character in each
I have a table which is being dynamically populated, each row contains two textfields
I have multiple textfields on my view, and each time a textfield is taped
In my iPad app I have two textfields. One displays the normal, default textfield
Class SampleFiveA extends JPanel. This contains textfields, one below the other, each of which
Let's see: i have to views each with a couple of textfields. One was
I have dynamic number of textfields in my tableview, I put each textfield into
I have an html page with one or more textareas, each of which has
I have multiple textfields on a UIView. I resign for a previous textField in
Java 1.5, Linux I do have a screen which contains different textareas and textfields.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.