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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:46:15+00:00 2026-05-15T06:46:15+00:00

I have a TableViewController that is using a grouped Style and has two(2) sections.

  • 0

I have a TableViewController that is using a grouped Style and has two(2) sections. The first section has 4 rows and the second section has 3 rows. I have placed a UILabel and a UITextField in each cell, and have a custom method(textFieldDone:) to handle the cursor movement to the next text field when the return key is press.

This works fine and dandy if there is only one section, but I have two 🙁 and yes I need two:)

so I started codin’ up an answer, but got results that just don’t work, I did notice during my debugging that cell Identifier (I use Two) is only showing the one (in the debug consol) and it’s the first one only (Generic Cell).

    - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITableViewCell *cell   = nil;

    switch (indexPath.section) 
    {
        case AUTO_DETAILS:
        {
            static NSString *cellID = @"GenericCell";

            cell = [tableView dequeueReusableCellWithIdentifier:cellID];

            if (cell == nil)
            {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 
                                               reuseIdentifier:cellID] autorelease];

                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)];
                label.tag           = kLabelTag;
                label.font          = [UIFont boldSystemFontOfSize:14];
                label.textAlignment = UITextAlignmentRight;
                [cell.contentView addSubview:label];
                [label release];


                UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(90, 12, 200, 25)];
                textField.clearsOnBeginEditing = NO;
                [textField setDelegate:self];
                [textField addTarget:self action:@selector(topTextFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
                [cell.contentView addSubview:textField];
            }

            NSInteger   row         = [indexPath row];
            UILabel     *label      = (UILabel *)[cell viewWithTag:kLabelTag];
            UITextField *textField  = nil;

            for (UIView *oneView in cell.contentView.subviews)
            {
                if ([oneView isMemberOfClass:[UITextField class]])
                    textField = (UITextField *)oneView;
            }

            label.text = [topCellLabels objectAtIndex:row];
            NSNumber *rowAsNum = [[NSNumber alloc] initWithInt:row];


            switch (row) 
            {
                case kMakeRowIndex:
                    if ([[tempValues allKeys] containsObject:rowAsNum])
                        textField.text = [tempValues objectForKey:rowAsNum];
                    else
                        textField.text = automobile.make;
                    break;
                case kModelRowIndex:
                    if ([[tempValues allKeys] containsObject:rowAsNum])
                        textField.text = [tempValues objectForKey:rowAsNum];
                    else
                        textField.text = automobile.model;
                    break;
                case kYearRowIndex:
                    if ([[tempValues allKeys] containsObject:rowAsNum])
                        textField.text = [tempValues objectForKey:rowAsNum];
                    else
                        textField.text = automobile.year;
                    break;
                case kNotesRowIndex:
                    if ([[tempValues allKeys] containsObject:rowAsNum])
                        textField.text = [tempValues objectForKey:rowAsNum];
                    else
                        textField.text = automobile.notes;
                    break;
                default:
                    break;
            }

            if (textFieldBeingEdited == textField)
            {
                textFieldBeingEdited = nil;
            }

            textField.tag = row;
            [rowAsNum release];
            break;
        }
        case AUTO_REGISTRATION:
        {

            static NSString *AutoEditCellID = @"AutoEditCellID";

            cell = [tableView dequeueReusableCellWithIdentifier:AutoEditCellID];

            if (cell == nil)
            {
                cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue2 
                                              reuseIdentifier:AutoEditCellID] autorelease];

                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(10, 10, 75, 25)];
                label.tag           = kLabelTag;
                label.font          = [UIFont boldSystemFontOfSize:14];
                label.textAlignment = UITextAlignmentRight;
                [cell.contentView addSubview:label];
                [label release];


                UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(90, 12, 200, 25)];
                textField.clearsOnBeginEditing = NO;
                [textField setDelegate:self];
                [textField addTarget:self action:@selector(bottomTextFieldDone:) forControlEvents:UIControlEventEditingDidEndOnExit];
                [cell.contentView addSubview:textField];
            }


            NSInteger   row         = [indexPath row];
            UILabel     *label      = (UILabel *)[cell viewWithTag:kLabelTag];
            UITextField *textField  = nil;

            for (UIView *oneView in cell.contentView.subviews)
            {
                if ([oneView isMemberOfClass:[UITextField class]])
                    textField = (UITextField *)oneView;
            }

            label.text = [bottomCellLabels objectAtIndex:row];
            NSNumber *rowAsNum = [[NSNumber alloc] initWithInt:row];

            switch (row) 
            {
                case 0:
                    if ([[tempValues allKeys] containsObject:rowAsNum])
                        textField.text = [tempValues objectForKey:rowAsNum];
                    else
                        textField.text = automobile.vinNumber;
                    break;
                case 1:
                    if ([[tempValues allKeys] containsObject:rowAsNum])
                        textField.text = [tempValues objectForKey:rowAsNum];
                    else
                        textField.text = automobile.policyNumber;
                    break;
                case 2:
                    if ([[tempValues allKeys] containsObject:rowAsNum])
                        textField.text = [tempValues objectForKey:rowAsNum];
                    else
                        textField.text = automobile.licensePlate;
                    break;
                default:
                    break;
            }

            if (textFieldBeingEdited == textField)
            {
                textFieldBeingEdited = nil;
            }

            textField.tag = row;
            [rowAsNum release];
            break;
        }
        default:
            break;
    }
    return cell;
}

Now remember that the first section is working fine and the code for that method is this:

-(IBAction)topTextFieldDone:(id)sender 
{
    UITableViewCell *cell               = (UITableViewCell *)[[sender superview] superview];
    UITableView     *table              = (UITableView *)[cell superview];
    NSIndexPath     *textFieldIndexPath = [table indexPathForCell:cell];

    NSUInteger row = [textFieldIndexPath row];
    row++;

    if (row > kNumOfEditableRows)
        row = 0;

    NSUInteger newIndex[] = {0, row};
    NSIndexPath     *newPath    = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
    UITableViewCell *nextCell   = [self.tableView cellForRowAtIndexPath:newPath];
    UITextField     *nextField = nil;

    for (UIView *oneView in nextCell.contentView.subviews) 
    {
        if ([oneView isMemberOfClass:[UITextField class]])
            nextField = (UITextField *)oneView;
    }
    [nextField becomeFirstResponder];

}

It was my idea to just create a second method (secondSectionTextFieldDone:) like this

-(IBAction)bottomTextFieldDone:(id)sender 
{
    UITableViewCell *cell               = (UITableViewCell *)[[sender superview] superview];
    UITableView     *table              = (UITableView *)[cell superview];
    NSIndexPath     *textFieldIndexPath = [table indexPathForCell:cell];

    NSUInteger row = [textFieldIndexPath row];
    row++;

    if (row > 3)
        row = 0;

    NSUInteger newIndex[] = {0, row};
    NSIndexPath     *newPath    = [[NSIndexPath alloc] initWithIndexes:newIndex length:2];
    UITableViewCell *nextCell   = [self.tableView cellForRowAtIndexPath:newPath];
    UITextField     *nextField = nil;

    NSString *string = [NSString stringWithFormat:@"AutoEditCellID"];
    for (UIView *oneView in nextCell.contentView.subviews) 
    {
        NSLog(@"%@", nextCell.reuseIdentifier); /* DEBUG LOG */
        if ([oneView isMemberOfClass:[UITextField class]] && (nextCell.reuseIdentifier == string))
            nextField = (UITextField *)oneView;
    }

    [nextField becomeFirstResponder];

}

but the result does not solve the issue.

so my question is, how can i get the cursor to jump to the next textfield in the section that it is in, If there is one, and if not, then send a message “resignFirstResponder” so that, the keyboard goes away.

  • 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-15T06:46:16+00:00Added an answer on May 15, 2026 at 6:46 am

    implement UITextFieldDelegate

    yourFirstTextFeld.delegate = self;
    yourSecondTextFeld.delegate=self;
    

    implement this method

    - (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
     if(theTextField==yourFirstTextFeld){
         [yourSecondTextFeld becomeFirstResponder];
     }
     return YES;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 424k
  • Answers 424k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer I've used IoC to abstract this away with some success.… May 15, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer To preallocate resources and later start the thread almost immediately.… May 15, 2026 at 11:54 am
  • Editorial Team
    Editorial Team added an answer As fiirhok kindly pointed out, the solution is simply to… May 15, 2026 at 11:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.