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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T04:55:13+00:00 2026-06-12T04:55:13+00:00

I have a search button and when user clicks it I am displaying UISearchBar

  • 0

I have a search button and when user clicks it I am displaying UISearchBar programmatically. Width of Searchbar is (200) not full screen. I am searching like a MSWord and displaying the content in searchbar’ tableview. But when user is in middle of search and changed orientation how should I control the search bar width, i.e., self.searchDisplayController.searchBar.frame and self.searchDisplayController.searchResultsTableView.frame.

Below is the piece of code that used to create the searchbar:

-(IBAction)searchBar:(id)sender
{
    if(!searching)
    {
        searching = YES;
        sBar.frame = CGRectMake(500, 50,250, 44);
        [self.view addSubview:sBar];
        [searchController setActive:YES animated:YES];
        [sBar becomeFirstResponder];

        if((currentOrientation == UIInterfaceOrientationLandscapeLeft)  || 
           (currentOrientation ==  UIInterfaceOrientationLandscapeRight))
        {
            self.searchDisplayController.searchBar.frame = CGRectMake(755, 50, 250, 44);
        }
        else 
        {
            self.searchDisplayController.searchBar.frame = CGRectMake(500, 50, 250, 44);
        }
    }
}


- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString{
    [self filterContentForSearchText:searchString scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:[self.searchDisplayController.searchBar selectedScopeButtonIndex]]];

    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption
{
    [self filterContentForSearchText:[self.searchDisplayController.searchBar text] scope:
     [[self.searchDisplayController.searchBar scopeButtonTitles] objectAtIndex:searchOption]];

    // Return YES to cause the search result table view to be reloaded.
    return YES;
}

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller{
    /*
     Bob: Because the searchResultsTableView will be released and allocated automatically, so each time we start to begin search, we set its delegate here.
     */
    [self.searchDisplayController.searchResultsTableView setDelegate:self];
    [self.searchDisplayController.searchResultsTableView setBackgroundColor:[UIColor colorWithRed:1 green:1 blue:204/255.0 alpha:1.0]];
}

- (void)searchDisplayControllerDidEndSearch:(UISearchDisplayController *)controller{
    /*
     Hide the search bar
     */

    float animateTime = 0.3;
    CGRect viewFrame = sBar.frame;
    viewFrame.origin.y -= (viewFrame.size.height);

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:animateTime];

    sBar.frame = viewFrame;

    [UIView commitAnimations];
    [self performSelector:@selector(animationDone) withObject:nil afterDelay:0.3];

}

-(void)animationDone
{
    [sBar removeFromSuperview];
    searching = NO;
}


-(void)searchDisplayController:(UISearchDisplayController *)controller didShowSearchResultsTableView:(UITableView *)tableView 
{
    if((currentOrientation == UIInterfaceOrientationLandscapeLeft)  || 
       (currentOrientation ==  UIInterfaceOrientationLandscapeRight))
    {
        tableView.frame = CGRectMake(755, 100, 250, 400);
    }
    else 
    {
        tableView.frame = CGRectMake(500, 100, 250, 400);
    }
}



- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
                                duration:(NSTimeInterval)duration
{
    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
    currentOrientation = toInterfaceOrientation;



    if((currentOrientation == UIInterfaceOrientationLandscapeLeft)  || 
       (currentOrientation ==  UIInterfaceOrientationLandscapeRight))
    {

        //Search
        btnSearch.frame = CGRectMake(920, 5, 40, 40);

        self.searchDisplayController.searchBar.frame = CGRectMake(755, 50, 250, 44);
        self.searchDisplayController.searchResultsTableView.frame = CGRectMake(755, 100, 250, 400);
    }
    else 
    {

        //Search
        btnSearch.frame = CGRectMake(666, 5, 40, 40);

        self.searchDisplayController.searchBar.frame = CGRectMake(500, 50, 250, 44);
        self.searchDisplayController.searchResultsTableView.frame = CGRectMake(500, 100, 250, 400);
    }
}

I am able to create and functionality which is working fine. But only issue is when user change the orinentation its not properly setting searchbar’ width.
My application needs to be delivered this friday. Please answere me asap.

  • 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-12T04:55:14+00:00Added an answer on June 12, 2026 at 4:55 am

    Answering my question to close this thread as well to help others.

    (1) In willRotateToInterfaceOrientation its able to set UISearchBar origin. Width is coming as 768 (full screen width of iPad in Portrait) but origin seems to be set here.

    (2) After orientation change finished we can set the search bar width. With small animation it will be smooth resize.

    (3) I am calling resetFrame at both pre & post orientation APIs to avoid some sudden JURK kind for searchBar.

    Below is the solution i used for my app..

    - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation 
                                    duration:(NSTimeInterval)duration
    {
        [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
        currentOrientation = toInterfaceOrientation;
    
    
    
        [self resetSearchResourcesFrames];  // Set the origin of UISearchBar
    }
    
    - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
    {
        [super didRotateFromInterfaceOrientation:fromInterfaceOrientation];
        [UIView beginAnimations:@"" context:nil]; //Animation for smooth resizing of search tableview only
        [UIView setAnimationDuration:0.2];
        [self resetSearchResourcesFrames];  // Width rotation only possible after rotation
        [UIView commitAnimations];
    }
    
    -(void)resetSearchResourcesFrames
    {
        if(([buttonGridViewController sharedInstance].currentOrientation == UIInterfaceOrientationLandscapeLeft)  || 
           ([buttonGridViewController sharedInstance].currentOrientation ==  UIInterfaceOrientationLandscapeRight))
        {
            //Search
            btnSearch.frame = CGRectMake(920, 5, 40, 40);
    
            self.searchDisplayController.searchBar.frame = CGRectMake(755, 50, 250, 44);
            self.searchController.searchResultsTableView.frame = CGRectMake(755, 100, 250, 400);
        }
        else 
        {
            //Search
            btnSearch.frame = CGRectMake(666, 5, 40, 40);
    
            self.searchDisplayController.searchBar.frame = CGRectMake(500, 50, 250, 44);
            self.searchController.searchResultsTableView.frame = CGRectMake(500, 100, 250, 400);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

in my app i have a button named Search, When the user clicks the
I have an input text box and a search submit button, and when user
I want to close my UISearchDisplayController when the user clicks the Search button since
I have a search field and button. When the user searches something like cat
I have a form which contains textboxes,search button. when user enter the values and
I have a partial view that when the user clicks a button, some data
I have a textfield where the user enters some number and clicks the search
I have a search button tied to an update panel as a trigger like
I have a search box and search button. I want to call a javascript
I have a simple ProgressDialog but I realized if I press the search button

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.