У меня есть следующий код для установки моего UISearchController
- (void)viewDidLoad {
[super viewDidLoad];
// Arrays init & sorting.
self.cities = [@[@"Boston", @"New York", @"Oregon", @"Tampa", @"Los Angeles", @"Dallas", @"Miami", @"Olympia", @"Montgomery", @"Washington", @"Orlando", @"Detroit"] sortedArrayUsingComparator:^NSComparisonResult(NSString *obj1, NSString *obj2) {
return [obj2 localizedCaseInsensitiveCompare:obj1] == NSOrderedAscending;
}];
self.results = [[NSMutableArray alloc] init];
// A table view for results.
UITableView *searchResultsTableView = [[UITableView alloc] initWithFrame:self.tableView.frame];
searchResultsTableView.dataSource = self;
searchResultsTableView.delegate = self;
// Registration of reuse identifiers.
[searchResultsTableView registerClass:UITableViewCell.class forCellReuseIdentifier:Identifier];
[self.tableView registerClass:UITableViewCell.class forCellReuseIdentifier:Identifier];
// Init a search results UITableViewController and setting its UITableView.
self.searchResultsTableViewController = [[UITableViewController alloc] init];
self.searchResultsTableViewController.tableView = searchResultsTableView;
// Init a UISearchController with its UITableViewController for results.
self.searchController = [[UISearchController alloc] initWithSearchResultsController:self.searchResultsTableViewController];
self.searchController.searchResultsUpdater = self;
self.searchController.delegate = self;
// Make an appropriate size for UISearchBar and add it as a header view for initial UITableView.
[self.searchController.searchBar sizeToFit];
self.tableView.tableHeaderView = self.searchController.searchBar;
// Enable presentation context.
self.definesPresentationContext = YES;
}
Это работает хорошо, за исключением iOS 11. Кажется, есть две проблемы. Во-первых, когда я ищу, между панелью таблицы и панелью поиска есть разрыв.
![enter image description here](https://i.stack.imgur.com/RYyeum.png)
Другая проблема заключается в том, что когда я выхожу из UISearchController
, первая ячейка в tableView слегка обрезается панелью поиска.
![enter image description here](https://i.stack.imgur.com/m8CVym.png)
Есть ли способ исправить эту проблему?