好吧,我終於有了解決方案,但同時我知道這不是最好的解決方案。
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString {
CGRect newFrame = [self.view.superview convertRect:self.searchDisplayController.searchResultsTableView.superview.superview.frame toView:nil];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
self.searchDisplayController.searchResultsTableView.superview.superview.frame = CGRectMake(0, -40, self.tableView.frame.size.width, window.bounds.size.height - newFrame.origin.y);
return YES;
}
和
- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar {
CGRect newFrame = [self.view.superview convertRect:self.searchDisplayController.searchResultsTableView.superview.superview.frame toView:nil];
UIWindow *window = [UIApplication sharedApplication].keyWindow;
self.searchDisplayController.searchResultsTableView.superview.superview.frame = CGRectMake(0, 4, self.tableView.frame.size.width, window.bounds.size.height - newFrame.origin.y);
return YES;
}
終於爲內容大小:
- (void)searchDisplayController:(UISearchDisplayController *)controller didHideSearchResultsTableView:(UITableView *)tableView {
[[NSNotificationCenter defaultCenter] removeObserver:self name:UIKeyboardWillHideNotification object:nil];
}
- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillHide) name:UIKeyboardWillHideNotification object:nil];
}
- (void) keyboardWillHide {
UITableView *tableView = [[self searchDisplayController] searchResultsTableView];
[tableView setContentInset:UIEdgeInsetsZero];
[tableView setScrollIndicatorInsets:UIEdgeInsetsZero];
}
這可能是一個重複:http://stackoverflow.com/questions/18989587/ios-7- uisearchdisplaycontroller-search-bar-disappears –
不,它不是。但謝謝你的嘗試! –