Ios 当我第二次轻按时,UISearchBar将消失

Ios 当我第二次轻按时,UISearchBar将消失,ios,objective-c,ios7,uisearchbar,uisearchdisplaycontroller,Ios,Objective C,Ios7,Uisearchbar,Uisearchdisplaycontroller,我有一个带有UIViewController的应用程序,其中包含UISegmentView、UISearchDisplayController和UITableView,如图所示: 当我点击搜索栏时,一切都很好。键盘出现,我可以进行搜索活动。但当我第二次点击搜索栏后,它消失了——在第二张图片上: 当我加上: - (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar { self.searchDisplayController.sea

我有一个带有UIViewController的应用程序,其中包含UISegmentView、UISearchDisplayController和UITableView,如图所示:

当我点击搜索栏时,一切都很好。键盘出现,我可以进行搜索活动。但当我第二次点击搜索栏后,它消失了——在第二张图片上:

当我加上:

- (void)searchBarTextDidBeginEditing:(UISearchBar *)searchBar {
self.searchDisplayController.searchResultsTableView.frame = CGRectMake(0, 20,     self.tableView.frame.size.width, self.tableView.frame.size.height);
}
我可以在searchResultsTableView下看到搜索栏:


有人能帮我吗?谢谢大家!

好的,我终于找到了解决方案,但同时我知道这不是最好的解决方案

- (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;
}

最后,对于内容大小:

- (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];
}

这可能是:不,不是。但是谢谢你的尝试!
- (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];
}