关于UISearchDisplayController的一个坑

来源:互联网 发布:岳游网络千炮捕鱼ol1.1 编辑:程序博客网 时间:2024/05/16 02:11

在使用UISearchDisplayController的时候,会发现输入文字搜索列出结果时, UISearchDisplayController的tableView的Frame会发生变化 导致显示不正确. 在VC中添加一下代码可以解决

- (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 *)aNotification {        NSDictionary* info = [aNotification userInfo];        CGSize kbSize = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue].size;        UITableView *tableView = [self.searchDisplayController searchResultsTableView];        [tableView setContentInset:UIEdgeInsetsMake(0, 0, kbSize.height, 0)];        [tableView setScrollIndicatorInsets:UIEdgeInsetsMake(0, 0, kbSize.height, 0)];}

在显示结果的时候重置一下UISearchDisplayController里tableView 的frame

0 0