2014-10-29 15 views
7

Próbuję zrozumieć, dlaczego cały pasek nawigacyjny znika, gdy zaczynam wpisywać w UISearchController.searchBar. Ładuje się poprawnie i animuje poprawnie, ale tracę aktywny NavBar po uruchomieniu pisanie na maszynie. Oto kod, aby załadować searchController z viewDidLoad:Pasek nawigacyjny znika po wpisaniu w polu tekstowym UISearchController

UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; 

    searchResultsController.tableView.dataSource = self; 
    searchResultsController.tableView.delegate = self; 
    searchResultsController.tableView.backgroundColor = [UIColor redColor];  

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController]; 
    self.searchController.delegate = self; 
    self.searchController.searchResultsUpdater = self; 
    self.searchController.dimsBackgroundDuringPresentation = YES; 
    self.searchController.hidesNavigationBarDuringPresentation = NO; 

    [self.searchController.searchBar sizeToFit]; 

    self.tableView.tableHeaderView = self.searchController.searchBar; 
    self.definesPresentationContext = NO; 

A oto wynik po zacznę wpisując:

enter image description here

zauważyć, jak widok tabeli istnieje, ale wydaje się, że zajmują przestrzeń kontrolera nawigacyjnego i rozciągają się w dół do pierwszego nagłówka sekcji. Jakieś pomysły?

Dzięki.

+0

Rozwiązałeś to? – eestein

+0

opublikował rozwiązanie poniżej, ale nie jestem pewien, gdzie dokładnie był problem. =] – 4m1r

+0

np. Dzięki, przyjrzę to – eestein

Odpowiedz

2

Musisz ustawić definicjeContentContext na YES. Od przykład jabłka:

// Search is now just presenting a view controller. As such, normal view controller 
// presentation semantics apply. Namely that presentation will walk up the view controller 
// hierarchy until it finds the root view controller or one that defines a presentation context. 

self.definesPresentationContext = YES 
0

to praca dla mnie

self.navigationController.navigationBar.translucent = true;

0

Tak, byłem w końcu w stanie rozwiązać ten problem z tym następującej sekwencji startowej. Jednak nie jestem zbyt pewien, co zrobiłem, aby tak się stało. Trochę zajęte teraz, więc wkleję to rozwiązanie i zaakceptuję rozwiązanie, jeśli ktoś będzie mógł je dokładnie zlokalizować.

- (void)loadSearchBar 
{ 

    NSLog(@"Loading SearchBar"); 

    UITableViewController *searchResultsController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; 
    UITableView *myTv = [[UITableView alloc] initWithFrame:[[UIScreen mainScreen] bounds] style:UITableViewStylePlain]; 
    searchResultsController.tableView = myTv; 
    searchResultsController.tableView.dataSource = self; 
    searchResultsController.tableView.delegate = self; 
    searchResultsController.tableView.keyboardDismissMode = UIScrollViewKeyboardDismissModeOnDrag; 
    searchResultsController.tableView.sectionIndexColor = [UIColor colorWithHexString:linkBlue]; 

    self.searchResultsController = searchResultsController; 

    self.searchController = [[UISearchController alloc] initWithSearchResultsController:searchResultsController]; 
    self.searchController.delegate = self; 
    self.searchController.searchResultsUpdater = self; 
    self.searchController.dimsBackgroundDuringPresentation = YES; 
    self.searchController.hidesNavigationBarDuringPresentation = NO; 
    self.searchController.searchBar.frame = CGRectMake(self.searchController.searchBar.frame.origin.x, self.searchController.searchBar.frame.origin.y, self.searchController.searchBar.frame.size.width, 44.0); 

    self.searchBar = self.searchController.searchBar; 
    self.searchBar.autocorrectionType = UITextAutocorrectionTypeNo; 
    self.searchBar.autocapitalizationType = UITextAutocapitalizationTypeNone; 
    self.searchBar.delegate = self; 
    self.searchBar.translucent = YES; 
    self.tableView.tableHeaderView.layer.zPosition++; 

    self.tableView.tableHeaderView = self.searchController.searchBar; 
    self.definesPresentationContext = YES; 

    //add color to search field 
    UIView *subviews = [self.searchBar.subviews lastObject]; 
    UITextField *textView = (id)[subviews.subviews objectAtIndex:1]; 

    textView.backgroundColor = [UIColor colorWithHexString:textFieldBlue]; 

} 
Powiązane problemy