having the same issue as already posted (non of the answers works..), my table is a fixed width, and in iOS 10.x the searchbar (which is in the tableviewheader), stays the same size when typing. However in iOS 11, it jumps to the top of the screen and gets stretched out over the total width. All options tried;
self.definesPresentationContext = YES;
tableHeaderView.clipsToBounds = YES;
etc
but nothing seems to change.. it still jumps to the top full width..
Any other options?
Xcode 9 GM with iOS 11 (Xcode 9 GM with iOS 10.x and it all works fine)
First you need to add UISearchControllerDelegate
then set your delegate
self.searchController.delegate=self;
Place a new view which will hold your searchController
-(void) viewDidLoad{
UIView *searchContainerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.searchTable.frame.size.width, 30)];
searchContainerView.layer.masksToBounds=YES;
searchContainerView.clipsToBounds=YES;
self.tableView.tableHeaderView=searchContainerView;
self.searchController.searchBar.layer.masksToBounds=YES;
self.searchController.searchBar.clipsToBounds=YES;
[searchContainerView addSubview:self.searchController.searchBar];
[self.searchController.searchBar setFrame:CGRectMake(0, 0, 300, 30)];//Make sure that your header view and searchcontroller size is same
}
Then add these delegate methods
- (void)didPresentSearchController:(UISearchController *)searchController{
[searchController.searchBar setFrame:CGRectMake(0, 0, 300, 30)];
}
- (void)didDismissSearchController:(UISearchController *)searchController{
[searchController.searchBar setFrame:CGRectMake(0, 0, 300, 30)];
}
That worked for me, I hope you will make it work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With