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

后端 未结 2 817
盖世英雄少女心
盖世英雄少女心 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];
    }
    
    0 讨论(0)
  • 2020-12-07 16:35

    I had this exact problem. The solution posted on the developer forums here worked for me. Not sure if it's a bug in iOS 7 or just that they changed the way they're doing things but this is the only solution that I found solved my problem.

    Solution from the forum post for the lazy:

    - (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];
    
    }
    
    0 讨论(0)
提交回复
热议问题