1

I'm using a UISearchController and it is working fine. However it is leaving a blank space over the search bar (when it is focused) which partially hides the status bar. This espace

I already tried setting the self.edgesForExtendedLayout = UIRectEdgeNone also self.navigationController.extendedLayoutIncludesOpaqueBars = YES but the space is still there. I tried setting the self.definesPresentationContext = YES;but it generated that the searchBar take the status bar position like this.

I'm using a UIViewController embedded in a UINavigationController. This is the setUp that im implementing now:

@interface DirectoryViewController :  UIViewController <UITableViewDataSource , UITableViewDelegate ,UISearchBarDelegate, UISearchControllerDelegate, UISearchResultsUpdating>

@property (strong, nonatomic) NSMutableArray *personsArray;
@property (nonatomic, strong) UISearchController *searchController;
@property (nonatomic, strong) NSMutableArray *searchResults;


@implementation DirectoryViewController

- (void)viewDidLoad {
    [super viewDidLoad];
UINavigationController *searchResultsController = [[self storyboard] instantiateViewControllerWithIdentifier:@"TableSearchResultsNavController"];

    // Our instance of UISearchController will use searchResults
    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController];

    // The searchcontroller's searchResultsUpdater property will contain our tableView.
    self.searchController.searchResultsUpdater = self;
    self.searchController.delegate = self;
    self.searchController.searchBar.delegate = self;

    //Cancel button tint
    _searchController.searchBar.tintColor = [UIColor whiteColor];
    [self.searchController.searchBar setBackgroundImage:[UIImage imageNamed:@"navBar"]
                                                forBarPosition:0
                                                    barMetrics:UIBarMetricsDefault];

    if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) { /// iOS 7 or above
        self.edgesForExtendedLayout = UIRectEdgeNone;
    }

    self.navigationController.extendedLayoutIncludesOpaqueBars = YES;

}

I appreciate any help. Thanks

1 Answers1

0

I found the solution in This answer.

Changing the tableInsets:

    self.directoryTable.contentInset = UIEdgeInsetsMake(-10, 0, 0, 0);

when the searchController is becameFirstResponder

and

    self.directoryTable.contentInset = UIEdgeInsetsMake(0, 0, 0, 0);

when the search bar action is finished.

Community
  • 1
  • 1