0

I have written code for searchBar in Objective C for iOS devices and it is working fine on iPhone but when it comes to iPad it is changing its x value and due to which cancel button is also hiding.

Initially Search bar looks like:

enter image description here

After Clicking in search bar:

enter image description here

Does anybody face this issue and suggest me something in this ?

Here is the code:

self.searchController = [[UISearchController alloc] initWithSearchResultsController:nil];    
self.searchController.searchBar.delegate = self;
self.searchController.searchResultsUpdater = self;
self.searchController.dimsBackgroundDuringPresentation = NO;
followTableView.tableHeaderView = self.searchController.searchBar;
UISearchBar.appearance.tintColor = [UIColor whiteColor]; //Cancel button color

[self.searchController.searchBar sizeToFit];

tapGesture = [[UITapGestureRecognizer alloc]init];
[tapGesture addTarget:self action:@selector(tapGestureBtnAction:)];

self.searchController.searchBar.barTintColor = searchBarColor;


-(IBAction)tapGestureBtnAction:(id)sender
{
  [_searchController.searchBar resignFirstResponder];

  [self.view removeGestureRecognizer:tapGesture];
}

Thanks in advance.

UGandhi
  • 518
  • 1
  • 8
  • 28

4 Answers4

3

This happened to me as well, Just set this to NO.

self.definesPresentationContext = NO

check this: UISearchController Search Bar Position Drops 64 points

0

Thank you guys for participation.

By setting, self.definesPresentationContext = NO; The issue is resolved. I found this solution by following this: UISearchController Search Bar Position Drops 64 points

UGandhi
  • 518
  • 1
  • 8
  • 28
0

for swift 4.x, this worked for me

self.edgesForExtendedLayout = .bottom
Usman Shahid
  • 183
  • 2
  • 11
0

You can assign your UISearchController in viewWillAppear function.