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

  • Home
  • SEARCH
  • 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 5954889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:02:08+00:00 2026-05-22T18:02:08+00:00

I have 8 uitextfields that are for a password. Each textfield contains one letter

  • 0

I have 8 uitextfields that are for a password. Each textfield contains one letter from password. When I type one letter and after that when I press the 2nd key then focus moves to next textfield. But I want that, as soon as I finished typing first character, the focus should move to the next text field without pressing other key or pressing tab key. How can I do that? Any tutorial of sample code for that? The code I have used is as below.

- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
{
    [[NSNotificationCenter defaultCenter] addObserver: self selector: @selector(keyPressed:) name: UITextFieldTextDidChangeNotification object: nil];
    // Try to find next responder

    UIResponder* nextResponder = [textField.superview viewWithTag:nextTag];
    if (nextResponder) {
        // Found next responder, so set it.
        //nextTag += 1;
        [nextResponder becomeFirstResponder];
        if ([nextResponder tag] == 308) {
            //[self performSelector:@selector(checkPassCode) withObject:nil afterDelay:0.0];
            [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector(checkPassCode) userInfo:nil repeats:NO];
            lastResponder = nextResponder;
        }
        return YES;
    } else {
        [textField resignFirstResponder];
        return NO;
    }
}


-(void) keyPressed: (NSNotification*) notification
{
    nextTag += 1;
    [[NSNotificationCenter defaultCenter] removeObserver: self name:UITextFieldTextDidChangeNotification object: nil];
}
  • 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-22T18:02:08+00:00Added an answer on May 22, 2026 at 6:02 pm
    - (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
    
        NSString *finalString = [textField.text stringByReplacingCharactersInRange:range withString:string];
    
        if ( [finalString length] > 0 ) {
            textField.text = string;
    
            UIResponder* nextResponder = [textField.superview viewWithTag:(textField.tag + 1)];
            if (nextResponder) {
                [nextResponder becomeFirstResponder];
    
                // Your code for checking it.
            }
    
            return NO;
        }
    
        return YES;
    }
    

    Hope this helps.

    Swift 3.2

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let finalString: String? = (textField.text? as NSString).replacingCharacters(in: range, with: string)
        if (finalString?.characters.count ?? 0) > 0 {
            textField.text = string
            let nextResponder: UIResponder? = textField.superview?.viewWithTag((textField.tag + 1))
            if nextResponder != nil {
                nextResponder?.becomeFirstResponder()
                // Your code for checking it.
            }
            return false
        }
        return true
    }
    

    Swift 4.1

    func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool {
        let finalString: String? = (textField.text as NSString?)?.replacingCharacters(in: range, with: string)
        if finalString?.count > 0 {
            textField.text = string
            let nextResponder: UIResponder? = textField.superview?.viewWithTag(textField.tag + 1)
            if nextResponder != nil {
                nextResponder?.becomeFirstResponder()
                // Your code for checking it.
            }
            return false
        }
        return true
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Scenario: I have 4 UITextFields that only accept 1 character. Easy. Problem: After I
I have a UITableView that contains a UITextField in each cell. I can't seem
I have this method here that turns integer inputs from two UITextFields into binary
I have some simple UITextFields that bring up the Numberpad. I would like to
I have a view with two UITextField , one for username, one for password.
I have 4 UITextFields that I'm dynamically creating, in the viewDidLoad, which works good.
I have a UIControl type screen which has a fullscreen UIScrollView and UITextFields on
I have this simple if statement that check UItextfields if empty or not like
I'm using a UITextfield to input information. I have several UITextfields that need to
I have an ipad app, that as user does some actions, uitextfields and buttons,

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.