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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T01:58:20+00:00 2026-05-25T01:58:20+00:00

I have an application with a view that has text fields from the top

  • 0

I have an application with a view that has text fields from the top of the view to the bottom of the view. I needed it to scroll when editing the bottom fields so that the fields would be visible, but it’s not seeming to work correctly.

Following the Apple docs, I placed all of that code into my program (Listings 4-1, 4-2), and added the scrollView and activeField outlets to my header file and linked them to IB.

The problem is as soon as I click into a text field, ALL of the text fields go out of view until I dismiss the keyboard. They scroll down very far (again, far enough to where none of the fields are visible).

Does anyone know what that problem could be caused by?

I’m placing the code in here from the Apple Docs so you can see exactly what code I’m using without having to click away.

//my .h
    IBOutlet UIScrollView *scrollView;
    IBOutlet UITextField *activeField;

//.m
    // Call this method somewhere in your view controller setup code.
    - (void)registerForKeyboardNotifications
    {
        [[NSNotificationCenter defaultCenter] addObserver:self
                selector:@selector(keyboardWasShown:)
                name:UIKeyboardDidShowNotification object:nil];

   [[NSNotificationCenter defaultCenter] addObserver:self
             selector:@selector(keyboardWillBeHidden:)
             name:UIKeyboardWillHideNotification object:nil];

}

// Called when the UIKeyboardDidShowNotification is sent.
- (void)keyboardWasShown:(NSNotification*)aNotification
{
    NSDictionary* info = [aNotification userInfo];
    CGSize kbSize = [[info objectForKey:UIKeyboardFrameBeginUserInfoKey] CGRectValue].size;

    UIEdgeInsets contentInsets = UIEdgeInsetsMake(0.0, 0.0, kbSize.height, 0.0);
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;

    // If active text field is hidden by keyboard, scroll it so it's visible
    // Your application might not need or want this behavior.
    CGRect aRect = self.view.frame;
    aRect.size.height -= kbSize.height;
    if (!CGRectContainsPoint(aRect, activeField.frame.origin) ) {
        CGPoint scrollPoint = CGPointMake(0.0, activeField.frame.origin.y-kbSize.height);
        [scrollView setContentOffset:scrollPoint animated:YES];
    }
}

// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
    UIEdgeInsets contentInsets = UIEdgeInsetsZero;
    scrollView.contentInset = contentInsets;
    scrollView.scrollIndicatorInsets = contentInsets;
}
- (void)textFieldDidBeginEditing:(UITextField *)textField
{
    activeField = textField;
}

- (void)textFieldDidEndEditing:(UITextField *)textField
{
    activeField = 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-25T01:58:20+00:00Added an answer on May 25, 2026 at 1:58 am

    UPDATE: Below answer is outdated. For now you can use “TPkeyboardavoiding” library for handle all kind of text field operation in UIScrollView, UITableView & many more. Try it and let me know if any one have a problem in integration.

    Old Answer

    There is no need to register for the keyboard notifications for this functionality. In order to center the active textField the screen above the keyboard, you only have to set the contentOffset of the UIscrollView two methods as shown here:

    // called when textField start editting.
    - (void)textFieldDidBeginEditing:(UITextField *)textField
    {
        activeField = textField;
        [scrollView setContentOffset:CGPointMake(0,textField.center.y-60) animated:YES];
    }
    
    
    
    // called when click on the retun button.
    - (BOOL)textFieldShouldReturn:(UITextField *)textField
    {
    
    
        NSInteger nextTag = textField.tag + 1;
        // Try to find next responder
        UIResponder *nextResponder = [textField.superview viewWithTag:nextTag];
    
        if (nextResponder) {
            [scrollview setContentOffset:CGPointMake(0,textField.center.y-60) animated:YES];
            // Found next responder, so set it.
            [nextResponder becomeFirstResponder];
        } else {
            [scrollview setContentOffset:CGPointMake(0,0) animated:YES];
            [textField resignFirstResponder];   
            return YES;
        }
    
        return NO; 
    }
    

    Note: All TextField should have incremental tags Like 1,2,3 and so no. And set delegates to self.

    Thanks,

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

Sidebar

Related Questions

I have a plug-in to an Eclipse RCP application that has a view. After
I have an application, built using MVC, that produces a view which delivers summary
I have a java application that is connected to a view on a remote
I have created an iPhone application based on an OpenGL view. Now I would
I have a stored procedure that search a view using full text. I'm trying
I want to create an Android application that has a MapView at the top
I have an application with a view containing several subviews. The subviews did not
I have a WinForms application with a view where the user selects a single
In my iPhone application I have a table view. When user taps any row,
I have two threads in an Android application, one is the view thread, and

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.