iOS 7 UISearchDisplayController search bar disappears

前端 未结 4 558
别那么骄傲
别那么骄傲 2020-12-29 13:50

I was recently updating my app and came across this issue. When i start typing in the search bar the search bar disappears and i can only see the table view. I can still kee

相关标签:
4条回答
  • 2020-12-29 13:56
    -(void)setCorrectSearchBarFrames
    {
        //INFO: Here we set the frame to avoid overlay
        CGRect searchDisplayerFrame = self.searchDisplayController.searchResultsTableView.frame;
        searchDisplayerFrame.origin.y = 40.0;
        searchDisplayerFrame.size.height -= 40.0;
        self.searchDisplayController.searchResultsTableView.frame = searchDisplayerFrame;
    }
    

    Thanks Tihi. If I use this block of code the search bar be back !!

    Have fun, I hope it could help you.

    0 讨论(0)
  • 2020-12-29 13:58

    try resize searchResultsTableView frame on

    -(void)searchDisplayController:(UISearchDisplayController *)controller 
     didShowSearchResultsTableView:(UITableView *)tableView
    
    0 讨论(0)
  • 2020-12-29 13:58

    I almost had a mental breakdown, since I could not get the search bar to show in a new app project of mine. The search bar did not show up in the navigation controller, although I had done the following:

    1) Add a "Search Bar and Search Display Controller" component to my storyboard view controller (in the bar below the view, not into the view)

    2) In viewDidLoad, call "self.searchDisplayController.displaysSearchBarInNavigationBar = YES;"

    The only thing that happened was that I got a label (!) that said Search.

    After a looong time struggling, I created a new project and started to recreate the non-working one, piece by piece. I started with the storyboard...and now the search bar DID show. I then added libraries like Google Analytics, external components etc. Until the project was identical to the one that did not work...and now the problem was back! No search bar!

    As I started to remove stuff, I finally found that it was a category code file (which I do not refer, but that is in the project) that is called UISearchBar+SearchField and which defines a readonly property.

    The .h file looks like this:

    @interface UISearchBar (SearchField2)
    
    @property (nonatomic, readonly) UITextField *searchField;
    
    @end
    

    And the .m file looks like this

    #import "UISearchBar+SearchField.h"
    
    @implementation UISearchBar (SearchField)
    
    - (UITextField *)searchField {
        NSUInteger subViewCount = [self.subviews count];
        for (int i = 0; i < subViewCount; i++) {
            if ([[self.subviews objectAtIndex:i] isKindOfClass:[UITextField class]]) {
                return [self.subviews objectAtIndex:i];
            }
        }
        return nil;
    }
    
    @end
    

    As soon as I removed or renamed this property, everything started to work.

    This is very(!) specific to my insanely strange problem, but perhaps it helps someone.

    0 讨论(0)
  • 2020-12-29 14:19

    A little late, but I've encounter the same problem just recently. I wanted the search bar to be visible and active through all of the search, so the dimmed view, which overlaid it, was a big problem. For me the only thing that worked was changing the frame of the dimmed view (apparently it's not the same as changing the frame of searchResultsTableView). I've managed to do that with the following code:

    -(void)setCorrectFrames
    {
        // Here we set the frame to avoid overlay
        CGRect searchDisplayerFrame = self.searchDisplayController.searchResultsTableView.superview.frame;
        searchDisplayerFrame.origin.y = CGRectGetMaxY(self.searchDisplayController.searchBar.frame);
        searchDisplayerFrame.size.height -= searchDisplayerFrame.origin.y;
        self.searchDisplayController.searchResultsTableView.superview.frame = searchDisplayerFrame;    
    }
    
    -(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller
    {
        [self setCorrectFrames];
    }
    
    -(void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller
    {
        [self setCorrectFrames];
    }
    
    0 讨论(0)
提交回复
热议问题