2013-10-03 18 views

Odpowiedz

12

Rozwiązałem to przez dodanie NSNotificationCenter słuchacza

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

Nie zapomnij usunąć słuchacza

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

Regulacja contentSize tableview w sposobie powiadamiania

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

Ta [odpowiedź] (http://stackoverflow.com/a/19162257/467588) jest podobna, ale nieco krótsza;) – Hlung

12

Tutaj jest bardziej prosty i wygodny sposób, aby to zrobić na podstawie Hlung Posted linku:

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

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

} 

Uwaga: Oryginalny odpowiedź wykorzystuje NSNotificationCenter produkować takie same wyniki.

Powiązane problemy