2013-10-03 14 views

Antwort

12

ich dies durch Hinzufügen eines NSNotificationCenter Zuhörer gelöst sein

- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView { 
    //this is to handle strange tableview scroll offsets when scrolling the search results 
    [[NSNotificationCenter defaultCenter] addObserver:self 
              selector:@selector(keyboardDidHide:) 
               name:UIKeyboardDidHideNotification 
               object:nil]; 
} 

Vergessen Sie nicht, den Hörer zu entfernen

- (void)searchDisplayController:(UISearchDisplayController *)controller willHideSearchResultsTableView:(UITableView *)tableView { 
    [[NSNotificationCenter defaultCenter] removeObserver:self 
                name:UIKeyboardDidHideNotification 
                object:nil]; 
} 

einstellen tableview content in der Benachrichtigungsmethode

0 Hier
- (void)keyboardDidHide:(NSNotification *)notification { 
    if (!self.searchDisplayController.active) { 
     return; 
    } 
    NSDictionary *info = [notification userInfo]; 
    NSValue *avalue = [info objectForKey:UIKeyboardFrameEndUserInfoKey]; 
    CGSize KeyboardSize = [avalue CGRectValue].size; 
    CGFloat _keyboardHeight; 
    UIInterfaceOrientation orientation = [[UIApplication sharedApplication] statusBarOrientation]; 
    if (UIDeviceOrientationIsLandscape(orientation)) { 
     _keyboardHeight = KeyboardSize.width; 
    } 
    else { 
     _keyboardHeight = KeyboardSize.height; 
    } 
    UITableView *tv = self.searchDisplayController.searchResultsTableView; 
    CGSize s = tv.contentSize; 
    s.height -= _keyboardHeight; 
    tv.contentSize = s; 
} 
+2

Diese [Antwort] (http://stackoverflow.com/a/19162257/467588) ist ähnlich, aber ein bisschen kürzer;) – Hlung

12

ist ein einfacher und bequemer Weg, es zu tun, basierend auf hlung der geposteten Link:

- (void)searchDisplayController:(UISearchDisplayController *)controller willShowSearchResultsTableView:(UITableView *)tableView { 

    [tableView setContentInset:UIEdgeInsetsZero]; 
    [tableView setScrollIndicatorInsets:UIEdgeInsetsZero]; 

} 

Hinweis: Die ursprüngliche Antwort verwendet NSNotificationCenter die gleichen Ergebnisse zu erzielen.

Verwandte Themen