2015-05-26 73 views
2

顯示顯示以下內容:與導航欄iOS7 UISearchDisplayController錯誤不會自動隱藏

-> UINavigationBar 
-> UINavigationTransitionView 
    ->UITableView 
    ->UISearchDisplayController 
     ->UISearchBar 

當我打的搜索欄的searchDisplayController不隱藏導航欄,而不是它揭示了它的一半。

我不使用自動佈局(所以沒有約束),我使用UITableViewController,我不能使用新的UISearchController,我正在尋找一種解決方案,使其工作,因爲它應該或者不允許它擴大。這個問題只發生在iPad上。該項目支持iOS7及以上版本。

我試圖抓住一切都在下面的方法:

#pragma mark - UISearchDisplayController Delegate 

- (void)searchDisplayController:(UISearchDisplayController *)controller willHideSearchResultsTableView:(UITableView *)tableView { 
    self.onlineSearchRequestUUID = [NSUUID UUID]; 
    dispatch_async(self.searchSerialQueue, ^{ 
     if ([self.parentVC needsEmail]) { 
      self.capiContact->setFilter(CAPIContactFilter::WithEmail, ""); 
     } else { 
      self.capiContact->setFilter(CAPIContactFilter::All, ""); 
     } 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [self.parentVC.tableView reloadData]; 
     }); 
    }); 
} 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString { 
    dispatch_async(self.searchSerialQueue, ^{ 
     [self filterContentForSearchText:searchString 
            scope:[controller.searchBar scopeButtonTitles][[controller.searchBar selectedScopeButtonIndex]]]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [controller.searchResultsTableView reloadData]; 
      if ([searchString length] == 0) { 
       [self.parentVC.tableView reloadData]; 
      } 
     }); 
    }); 
    return NO; 
} 

- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchScope:(NSInteger)searchOption { 
    dispatch_async(self.searchSerialQueue, ^{ 
     [self filterContentForSearchText:[controller.searchBar text] 
            scope:[controller.searchBar scopeButtonTitles][searchOption]]; 
     dispatch_async(dispatch_get_main_queue(), ^{ 
      [controller.searchResultsTableView reloadData]; 
     }); 
    }); 
    return NO; 
} 

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar { 
    if (![self.tableView isEditing]) { 
     searchBar.showsScopeBar = YES; 
     [searchBar sizeToFit]; 


     _oldnavCol = [self.navigationController.view.backgroundColor copy]; 
     @try { 
      [self.navigationController.view setBackgroundColor:[[[[self.parentVC.searchDisplayController searchBar] subviews][0] subviews][1] barTintColor]]; 
     } 
     @catch (NSException *exception) { 
      LogDebug(@"%@", exception); 
     } 

     return YES; 
    } 
    return NO; 
} 

- (BOOL)searchBarShouldEndEditing:(UISearchBar *)searchBar { 
    double delayInSeconds = .5; 
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC)); 
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){ 
     if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) 
     { 
      [self.navigationController.view setBackgroundColor:_oldnavCol]; 
      _oldnavCol = nil; 
     } 
    }); 
    return YES; 
} 

- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { 
//Here is where i have tried most of my tries to make it work with hacks but with no luck. 
    //self.navigationController.navigationBar.translucent = YES; 
    if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { 
     self.searchDisplayController.searchBar.frame = CGRectMake(0, 0, self.tableView.frame.size.width, 88); 
    } 
} 

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope { 
    self.tableSearchText = searchText; 
//some code here 

    if ([searchText length]) { 
     [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; 
     dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{ 
      NSString *uuid = [self.onlineSearchRequestUUID UUIDString]; 
      //some more code here 
     }); 
    } 
} 

我不認爲我失去了一些東西。

任何幫助,將不勝感激。

回答

1
- (void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller { 

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) 
    { 
     [[[parentViewController navigationController] navigationBar] setHidden: YES]; 
    } 
} 

我的情況parentViewController或者是自己或self.parentVC和它的作品就像一個魅力。