UINavigationBar随UISearchDisplayController和UISearchBar消失

时间:2014-01-31 01:03:36

标签: ios uinavigationcontroller uinavigationbar uisearchbar uisearchdisplaycontroller

以下是发生的事情:

用户点击搜索并看到以下图片:

First 然后用户开始输入一个术语,一旦发生这种情况,NavigationBar就会消失。你在这里看到的是一个空的空间,导航栏被附加。我已经尝试了一切,无法弄清楚为什么这样做。并且ViewController不是NavigationController的根视图(THERE IS NO UINavigationController)。 Second

以下是我的搜索代表的相关代码:

- (void)filterContentForSearchText:(NSString*)searchText scope:(NSString*)scope
{
    if ([searchText length] == 0)
    {
        [self.aTableView reloadData];
        return;
    }

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF.title contains[cd] %@ OR     SELF.summary contains[cd] %@", searchText, searchText];
    mFilteredArray_ = [[self.parseResultsCanadaSection filteredArrayUsingPredicate:predicate] copy];

    [self.aTableView reloadData];

}

#pragma mark - UISearchDisplayController delegate methods
-(BOOL)searchDisplayController:(UISearchDisplayController *)controller
shouldReloadTableForSearchString:(NSString *)searchString
{
    [self filterContentForSearchText:searchString
                               scope:[[self.searchDisplayController.searchBar scopeButtonTitles]
                                      objectAtIndex:[self.searchDisplayController.searchBar
                                                     selectedScopeButtonIndex]]];


    return YES;
}

- (void)searchDisplayControllerDidBeginSearch:(UISearchDisplayController *)controller {

}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {

    mFilteredArray_ = nil;

    [self.aTableView reloadData];
}


- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText {

    mFilteredArray_ = nil;

    [self.aTableView reloadData];
}

2 个答案:

答案 0 :(得分:0)

尝试设置搜索栏的框架,以便在用户开始搜索时为屏幕设置动画,这就是我解决这个问题的方法。

-(void)searchDisplayControllerWillBeginSearch:(UISearchDisplayController *)controller {
    if (isIOSseven) {
        searching = YES;
        [UIView animateWithDuration:0.25 animations:^{
            searchBar.frame = CGRectMake(searchBar.frame.origin.x, 20, searchBar.frame.size.width, searchBar.frame.size.height);
            tableView.frame = CGRectMake(tableView.frame.origin.x, searchBar.frame.origin.y + searchBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 40);
        }];
    }
}

-(void)searchDisplayControllerWillEndSearch:(UISearchDisplayController *)controller {
    if (isIOSseven) {
    searching = NO;
    [UIView animateWithDuration:0.25 animations:^{
        searchBar.frame = CGRectMake(searchBar.frame.origin.x, 64, searchBar.frame.size.width, searchBar.frame.size.height);
        tableView.frame = CGRectMake(0, searchBar.frame.origin.y + searchBar.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 64);
    }];
}

答案 1 :(得分:0)

我解决这个问题的方法是添加一个UINavigationController。这似乎是妥善解决这个问题的唯一方法。