iOS 7 UISearchDisplayController search bar disappears

放肆的年华 提交于 2019-12-18 11:56:10

问题


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 keep on typing and the table view gets updated but i cannot see the search bar. Same settings works fine on iOS < 7

Any idea why this is happening ?


回答1:


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];
}



回答2:


try resize searchResultsTableView frame on

-(void)searchDisplayController:(UISearchDisplayController *)controller 
 didShowSearchResultsTableView:(UITableView *)tableView



回答3:


-(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.




回答4:


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.



来源:https://stackoverflow.com/questions/18989587/ios-7-uisearchdisplaycontroller-search-bar-disappears

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!