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 8660643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:18:15+00:00 2026-06-12T16:18:15+00:00

I’m using the following code to move to the next field using the UITextField

  • 0

I’m using the following code to move to the next field using the UITextField delegate and also I’m adding a toolbar to the keyboard with the previous, next and ok buttons. The code is working fine.

Like you see the keyboard return button logic is pretty generic, using the UITextField tags, and that’s good because I’m gonna use the piece of code all around. Now I will need to write the previous and next buttons logic, and I’m lost. Any ideas?

UPDATE (complete code, with some modifications, thanks to @8vius that spent some time with me in the chat to make it work):

//
// SigninViewController.m
//

#import "SigninViewController.h"

@implementation SigninViewController

@synthesize firstResponder = _firstResponder;
@synthesize toolbar;
@synthesize email;
@synthesize password;

- (void)move:(UIBarButtonItem*)sender {

    NSInteger tag = self.firstResponder.tag;

    if ([sender.title isEqualToString:@"Anterior"]) {
        tag -= 1;
    } else if ([sender.title isEqualToString:@"Próximo"]) {
        tag += 1;
    }

    UITextField *nextTextField = (UITextField*)[self.view viewWithTag:tag];

    if (nextTextField && tag > 0) {
        [nextTextField becomeFirstResponder];
    } else {
        [self.firstResponder resignFirstResponder];
        self.firstResponder = nil;
    }

}

- (void)ok:(id)sender {
    [self.view endEditing:YES];
    self.firstResponder = nil;
}

- (void)textFieldDidBeginEditing:(UITextField*)textField {
    self.firstResponder = textField;
}

- (BOOL)textFieldShouldReturn:(UITextField*)textField {

    NSInteger tag = textField.tag + 1;

    UITextField *nextTextField = (UITextField*)[self.view viewWithTag:tag];

    if (nextTextField) {
        [nextTextField becomeFirstResponder];
    } else {
        [textField resignFirstResponder];
        self.firstResponder = nil;
    }

    return NO;

}

- (void)viewDidLoad {

    [super viewDidLoad];

    self.email.delegate = self;
    self.password.delegate = self;

    if (self.toolbar == nil)
    {
        self.toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 44)];

        UIBarButtonItem* previous = [[UIBarButtonItem alloc] initWithTitle:@"Anterior" style:UIBarButtonItemStyleBordered target:self action:@selector(move:)];
        UIBarButtonItem* next = [[UIBarButtonItem alloc] initWithTitle:@"Próximo" style:UIBarButtonItemStyleBordered target:self action:@selector(move:)];
        UIBarButtonItem* space = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:(UIBarButtonSystemItemFlexibleSpace) target:nil action:nil];
        UIBarButtonItem* ok = [[UIBarButtonItem alloc] initWithTitle:@"Ok" style:UIBarButtonItemStyleBordered target:self action:@selector(ok:)];

        [self.toolbar setItems:[[NSArray alloc] initWithObjects:previous, next, space, ok, nil]];

        [self.toolbar setTranslucent:YES];
        [self.toolbar setTintColor:[UIColor blackColor]];
    }

    for (UIView* view in self.view.subviews) {
        if ([view isKindOfClass:[UITextField class]]) {
            [(UITextField*)view setInputAccessoryView:toolbar];
        }
    }

}

- (void)viewDidUnload {
    self.email = nil;
    self.password = nil;
    [super viewDidUnload];
}

@end
  • 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-06-12T16:18:17+00:00Added an answer on June 12, 2026 at 4:18 pm

    It’s quite simple, when you load your view you set the tag property on your text fields depending on the order you want them in, then you have to just traverse the tag element on the fields:

    - (void)toggleTextfield:(UIBarButtonItem *)sender {
      NSInteger nextTag = self.firstResponder.tag;
      if ([sender.title isEqualToString:@"Previous"] && nextTag > 1) {
        nextTag -= 1
      } else if ([sender.title isEqualToString:@"Next"]) {
        nextTag += 1;
      }
    
      UITextField *nextTextField = (UITextField *)[self.view viewWithTag:nextTag];
      if (nextTextField) {
        [nextTextField becomeFirstResponder];
      }
    }
    

    And keep track of who is the first responder:

    -(void)textFieldDidBeginEditing:(UITextField *)textField {
      self.firstResponder = textField;
    }
    
    - (BOOL)textFieldShouldReturn:(UITextField *)textField {
      [textField resignFirstResponder];
      self.firstResponder = nil;
      return YES;
    }
    

    And when you load your view, you bind the buttons to the toggle action:

      UIBarButtonItem *previousButton = [[UIBarButtonItem alloc] initWithTitle:@"Previous" 
                                                                         style:UIBarButtonItemStyleBordered 
                                                                        target:self
                                                                        action:@selector(toggleTextfield:)];
      UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:@"Next" 
                                                                         style:UIBarButtonItemStyleBordered 
                                                                        target:self
                                                                        action:@selector(toggleTextfield:)];
    

    In my case, for instance, I set up my text fields inside a table view, so in my cellForRowAtIndexPath method I set the tag property to be the row of the indexPath.

    EDIT: You have to set the firstResponder property for it to work.

    In your .h file:

    @property UIView *firstResponder
    

    In your .m file:

    @synthesize firstResponder = _firstResponder;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am reading a book about Javascript and jQuery and using one of the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have this code to decode numeric html entities to the UTF8 equivalent character.
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this

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.