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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:14:38+00:00 2026-05-25T12:14:38+00:00

Actually i am using next and previous button for moving one to another cell

  • 0

Actually i am using next and previous button for moving one to another cell and each cell has a textfield so when i am clicking on next button it moves me to the next cell and by getting this cell reference i can make the text field become first responder but when i am clicking on previous button it returns me no reference.
The code which i am using for next and previous is given below

- (IBAction)nextPrevious:(id)sender
{
    NSIndexPath *indexPath ;
    BOOL check = FALSE;

    if([(UISegmentedControl *)sender selectedSegmentIndex] == 1){
        if(sectionCount>=0 && sectionCount<8){
            //for next button
            check = TRUE;
            sectionCount = sectionCount+1;
            indexPath = [NSIndexPath indexPathForRow:0 inSection:sectionCount];
        }
    }else{
        //for previous button
        if(sectionCount>0 && sectionCount<=9){
            check = TRUE;
            sectionCount = sectionCount-1;

            indexPath = [NSIndexPath indexPathForRow:0 inSection:sectionCount];
        }
    }

    if(check == TRUE){
        //[registrationTbl reloadData];
        UITableViewCell *cell = [registrationTbl cellForRowAtIndexPath:indexPath];

        for(UIView *view in cell.contentView.subviews){
            if([view isKindOfClass:[UITextField class]]){
                    [(UITextField *)view becomeFirstResponder];
                    break;
            }
        }

        [registrationTbl scrollToRowAtIndexPath:indexPath
                               atScrollPosition:UITableViewScrollPositionTop
                                       animated:YES];


        // UITextField *field = (UITextField *) [cell.contentView viewWithTag:indexPath.section];
        // [field becomeFirstResponder];
    }

Any small suggestion will be much appreciated. Thanks in advance

  • 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-25T12:14:39+00:00Added an answer on May 25, 2026 at 12:14 pm

    The problem lies in the scrolling. When you scroll to the top of the next row, the previous row gets removed and reused for the last visible row, meaning that the method cellForRowAtIndexPath: will probably return null, as the cell is not currently available.

    The quick&dirty fix would involve scrolling to Middle or a little displaced so the cell is still visible. The not-so-quick-nor-dirty would involve making a procedure that scrolls the table to make sure the cell is visible, and then when the scrolling stops, set the textfield it as the first responder.

    (Edit) To explain a little more this last approach. Let’s say that you add a new variable NSIndexPath *indexPathEditing. The delegate method tableView:cellForRowAtIndexPath: would have:

    if (indexPathEditing && indexPathEditing.row == indexPath.row && indexPathEditing.section == && indexPath.section)
    {
        // Retrieve the textfield with its tag.
        [(UITextField*)[cell viewWithTag:<#Whatever#>] becomeFirstResponder];
        indexPathEditing = nil;
    }
    

    This means that if indexPathEditing is set, and the current row that is being loaded is visible, it will automatically set itself as the firstResponder.

    Then, for example (in your nextPrevious: method), all you need to do is:

    indexPathEditing = [NSIndexPath indexPathForRow:0 inSection:sectionCount];
    
    [registrationTbl scrollToRowAtIndexPath:indexPathEditing
                           atScrollPosition:UITableViewScrollPositionTop
                                   animated:YES];
    [registrationTbl reloadData];
    

    The row will appear, the tableView:cellForRowAtIndexPath: called, and it will get automatically set as the firstResponder.

    Also, notice that instead of doing a for with isKindOfClass, it’s easier to set a tag number, and then retrieve the object with viewWithTag:, I incorporated this in the example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to Visual C# Studio (actually using the Express edition, but another developer
Has anyone using .net actually worked out how to successfully sign a signature to
I need to getting the client ip address using javascript.Actually,our connection provider ip is
Actually I created a button using the cobogw widget library. But the button does
When using Java LinkedList how do you find out the element's next or previous
I am actually using h:selectOneRadio to display items, given to it from f:selectItems tag.
How do I do the following SQL in LINQ? I am actually using LINQ
Actually i am using the AsyncCalls library to execute an Query asynchronously in this
I'm running a Hadoop job using Hive actually that is supposed to uniq lines
Actually, I'm using this way. Do you have a better way? private bool AcceptJson(HttpRequest

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.