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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:09:40+00:00 2026-06-12T22:09:40+00:00

I write UISearchBar in my TopBar.m like this: _tempSearchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(44, 0, 320 –

  • 0

I write UISearchBar in my TopBar.m like this:

_tempSearchBar =[[UISearchBar alloc]initWithFrame:CGRectMake(44, 0, 320 - 44, 43)];
_tempSearchBar.barStyle=UIBarStyleDefault;
_tempSearchBar.placeholder=@"搜索";
[self addSubview:_tempSearchBar];

the result is like this, it is right.
enter image description here

and then I write UISearchDisplayController in another class like this:

_topBar.tempSearchBar.delegate = self;    
_searchDisplayController = [[UISearchDisplayController alloc] initWithSearchBar:_topBar.tempSearchBar contentsController:self];
[_searchDisplayController setDelegate:self];
[_searchDisplayController setSearchResultsDataSource:self];

the UISearchBarDelegate is like this:

#pragma mark -
#pragma mark UISearchBarDelegate
- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar
{
    [_searchDisplayController setActive:YES animated:YES];
}

when I click the UISearchBar , it show like this , the searchBar`s frame is changed.why?
enter image description here

when I cancel the UISearchDisplayController it is like this :
enter image description here

why the frame is changed? The width is changed from 320-44 to 320 by the UISearchDisplayController?
thanks.

  • 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-12T22:09:41+00:00Added an answer on June 12, 2026 at 10:09 pm

    The searchBar’s frame is changed by the UIKit, so I changed the searchBar’s frame back myself.

    I changed the searchBar’s frame in the below delegate.

    One is UISearchBar’s delegate:

    - (void)searchBarTextDidEndEditing:(UISearchBar *)searchBar {
        [searchBar setFrame:CGRectMake(44, 0, 320 - 44, 43)];
    }
    

    Another is UISearchDisplayController’s delegate:

    - (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller{
        [controller.searchBar setFrame:CGRectMake(44, 0, 320 - 44, 43)];
        [self.searchDisplayController.searchResultsTableView setDelegate:self];
    }
    

    It can work and I can get the right frame, but when I click the searchBar it will shake a little.

    It is not the best way to do it, but it can work. Does anyone have a better method?

    Update:
    I have debugged the UISearchBar and UISearchDisplayController for a few hours, but it has a little bug: When I endEditing the searchBar’s width will become 320px, and then will become my width. I can not change the cancelButton’s background color. So I wrote a custom SearchDisplayController, with a UISearchBar property and a UITableView property. It works well for me.

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

Sidebar

Related Questions

We write application with Corona SDK for new cell phones like iPhone4 and SamsungGalaxy2.
i write this in .emacs (require 'dired-x) (global-set-key (kbd C-x C-j) 'dired-jump) but when
I write a project using Prism . I have tow modules and this modules
I'm using a UISearchDisplayController with a UISearchBar. I put this UISearchBar in my app
Write a program in Java to calculate the following: 1+2-3+4-5 …-99+100 this program is
Write a package called Company. Under this package create one other package called salary.
Write a program that calculates Euler’s number e. To do this, first write a
I have found a tutorial on this website: http://jduff.github.com/2010/03/01/building-a-searchview-with-uisearchbar-and-uitableview/ ...but I am stuck here:
I have the following code for my UISearchBar: UISearchBar * searchBar = [[UISearchBar alloc]
Write a NASM macro: divide, which has 2 arguments, which specify unsigned integers in

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.