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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T13:41:53+00:00 2026-06-10T13:41:53+00:00

I have a UITableView and a navigation bar in a single screen of my

  • 0

I have a UITableView and a navigation bar in a single screen of my app. I want to navigation bar to be scrolled together with the rest of the table.

Note: I am currently implementing a UITableView that is added as a subview of a uiviewcontroller which is in turn part of a navigation controller

Can anyone advise me on how to do this?

  • 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-10T13:41:55+00:00Added an answer on June 10, 2026 at 1:41 pm

    In the following answer I’m hiding the real nav bar and replacing it with a fake bar. If you want to use the real nav bar instead, the code is still valid, just restore the original position of the bar in viewWillDisappear.

    Hide the navigation controller bar:

    self.navigationController.navigationBar.hidden = YES;
    

    Add a top bar as a subview of the current controller view.

    UIView *headerView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bar.png"]];
    [self.view addSubView:headerView];
    

    At this point you have a headerView and a tableView below. Save their original frames:

    @property (nonatomic,assign) CGRect initialTableRect;
    @property (nonatomic,assign) CGRect initialHeaderRect;
    
    // This is how many pixels you are going to scroll up under the clock bar.
    // To scroll your whole headerView, set it to self.headerView.frame.height
    @property (nonatomic,assign) NSInteger kHiddenPixels;    
    
    // viewDidLoad
    self.initialTableRect = self.tableView.frame;
    self.initialHeaderRect = self.headerView.frame;
    self.kHiddenPixels = self.headerView.frame.height;
    

    Add this in the view controller, which is also your table delegate:

    #pragma mark UIScrollViewDelegateMethods
    
    - (void)scrollViewDidScroll:(UIScrollView *)aScrollView
    {
        // 0 at the initial position, negative down, positive up
        CGPoint offset = aScrollView.contentOffset;
    
        if (offset.y>=0 && offset.y<=kHiddenPixels)
        {
            // move header
            CGRect newRect = self.initialHeaderRect;
            newRect.origin.y -= offset.y;
            self.headerView.frame = newRect;
    
            // move and resize table
            newRect = self.initialTableRect;
            newRect.origin.y -= offset.y;
            newRect.size.height += offset.y;
            self.tableView.frame = newRect;
        }
        else if (self.headerView.frame.origin.y!=0 || self.headerView.frame.origin.y!=kHiddenPixels)
        {
            // outside the scrolling area but frame is not on 0 or kHiddenPixels,
            // which means we skipped scroll because drag was to fast
    
            if (offset.y<0){
                // set initial position on header and table
                self.headerView.frame = self.initialHeaderRect;
                self.tableView.frame = self.initialTableRect;
            }
            else if (offset.y>kHiddenPixels)
            {
                // set scrolled up position on header
                CGRect rect = self.initialHeaderRect;
                rect.origin.y = -1*kHiddenPixels;
                self.headerView.frame = rect;
    
                // set scrolled up position on table            
                rect = self.initialTableRect;
                rect.size.height += kHiddenPixels;
                rect.origin.y -= kHiddenPixels;
                self.tableView.frame = rect;
            }
        }
    }
    

    This checks the table height and moves top bar as the table view scrolls. Since the tableView is moving over the are previously filled by the top bar, I’m also enlarging the size of the table view.

    edit: just uploaded an implementation in github with a top bar of 80 pixels and kHiddenPixels=35:

    enter image description here

    A possible enhancement: Right now, as the first row of the tableView scrolls under the top bar, the top bar scrolls below the clock bar. It would look more natural if the tableView and top bar scroll together until the top bar is gone, and then let the 1st row start scrolling under the top bar. Not sure how to do this, maybe with a pan gesture recognizer and disabling table scroll until the bar is hidden.

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

Sidebar

Related Questions

I have a UITableView which occupies the entire screen, besides a navigation bar. The
I have an app with a navigation bar at the top. On one view
Well in my app I have a navigation controller with a table view, and
I have a UITableview with a navigation bar on the top. I have a
I have a UITableView in a UINavigationController. On the navigation bar I have a
I have a navigation bar controller + tab bar controller + UITableview for the
I have an Edit button in my navigation bar, and I have an table
I have a UITableView on a UIViewController. And this table has say 5 visible
I have a controller displaying both a status bar and navigation bar, and containing
I have a UITableView (on a navigation controller stack) which is showing details for

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.