UISearchDisplayController's searchResultsTableView's ContentSize is incorrect. Bug in iOS 7?

后端 未结 2 822
盖世英雄少女心
盖世英雄少女心 2020-12-07 16:12

The below problem only occurs on an iOS 6.0/6.1 application running on an iOS 7.0+ device.

So I have a UISearchDisplayController that searches our API an

2条回答
  •  清歌不尽
    2020-12-07 16:29

    This system bug remains in iOS 8, and the accept answer's solution doesn't work anymore. So, you should use the following solution:

    -(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:(NSNotification*)notification {
        CGFloat height = [[[notification userInfo] objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size.height;
        UITableView *tableView = [[self searchDisplayController] searchResultsTableView];
        UIEdgeInsets inset;
        [[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0 ? (inset = UIEdgeInsetsMake(0, 0, height, 0)) : (inset = UIEdgeInsetsZero);
        [tableView setContentInset:inset];
        [tableView setScrollIndicatorInsets:inset];
    }
    

提交回复
热议问题