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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:51:25+00:00 2026-05-23T11:51:25+00:00

I’m working with UISearchBar for the first time and can’t quite make it do

  • 0

I’m working with UISearchBar for the first time and can’t quite make it do what I want.

When you activate the scope buttons, they cover the first row of the table. The only way to see all of your search results seem to be to hide the scope buttons when editing is finished; in my Googling on this I have seen that suggested.

I want the functionality that Mail has, where the scope buttons stay up as long as there is text in the search box, and you can see the search results change as you change the active scope button. But I can’t figure out any way to make this happen without having the first row of the table covered by the scope buttons. You can’t just scroll the table view down; the search bar is in the table view’s header, so the whole thing scrolls together.

Suggestions appreciated!

Updated after trying Andrew’s suggestion below.

One thing I forgot about is that in viewDidAppear I scroll the table view content up, so that the search box is off the top of the screen but can be scrolled down when needed. This is obviously part of my problem. So, in viewDidAppear I have

if (theSearchBar.showsScopeBar != YES) {
    [self.tableView setContentOffset:CGPointMake(0, 44) animated:YES];
}

In searchBarShouldBeginEditing, I now have:

[self.navigationController setNavigationBarHidden:YES];
[self.tableView setContentOffset:CGPointMake(0, -44) animated:YES];
[UIView beginAnimations:@"searchBarUp" context:nil];
[UIView setAnimationDuration:1.0f];
searchBar.frame = CGRectOffset(searchBar.frame, 0, -44);
[UIView commitAnimations];

This gives the correct result, but when the scope bars come up, there is a gap between the top of the view and the top of the search bar, and the first row is covered. Then the scroll bar (with the scope buttons) slides up into place. This obviously doesn’t look very good.

What I would expect the above code to do is:

  • hide the nav bar, which would put the top row of the table right below the status bar

  • scroll the table content back down, which would put the top of the search bar right below the status bar

  • move the search bar up so that there is a 44 pixel gap between the bottom of the search bar, to be filled in by the scope buttons

This does appear to be what happens, except you can see the gap left by the nav bar until the scroll bar moves up to meet it. You would think this could be fixed by hiding the nav bar last, but no… when I tried that I ended up with both the first row of the table covered and a nav bar sized hole between the status and search bars.

Another thing I find very odd is that if I use the above code snippet as is, except with animation:NO on the call to setContentOffset, I get a different result. In this case the first row of the table is not covered, but the search box is above the top of the view and cannot be scrolled down (it won’t stay). Only the scope buttons are visible. It doesn’t make sense to me that just turning off animation would change the outcome.

Now, you might think that with everything in the right place, displaying the search results would just work. But no. Even though the nav bar is now out of the picture, the search bar still comes up with a large gap above it, and the same adjustments to the table content and the search bar frame are required as above.

I should note that the code in viewWillAppear is only executed once, since we never leave the view, so it’s not the case that the table is being readjusted upwards each time.

I would love to understand what’s going on, as well as how to fix it, if anyone can help shed some light.

Updated again for clarity – when I say “fix it”, what I mean is make it look good without visible gaps when the pieces are moving into place. I don’t even necessarily want it animated; the sliding into position takes too long. But as I mentioned above, turning animation off makes things end up in the wrong place again.

Updated one last time – I got it to look much better by removing the animation block around the line to move the search bar. I guess that introduced a pause before the animation began. It’s good enough now, at least for the moment. I’m still accepting Andrew’s answer since he steered me in the right direction.

  • 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-23T11:51:26+00:00Added an answer on May 23, 2026 at 11:51 am

    You are using a UISearchDisplayController, right? If not, you should. It will take care of a lot of the work you are trying to do yourself, like hiding the navigation bar.

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

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I want use html5's new tag to play a wav file (currently only supported
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
i want to parse a xhtml file and display in UITableView. what is the
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
Does anyone know how can I replace this 2 symbol below from the string

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.