سؤال

Here's what's happening:

The user clicks search and sees the following image:

First Then the user starts typing in a term and as soon as that happens the NavigationBar disappears. What you're looking at here is an empty space where the Navigation Bar was attached. I've tried everything and cannot figure out why it's doing this. And no the ViewController is not a root view to a NavigationController (THERE IS NO UINavigationController). Second

Here's the relevant code for my search delegate:

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

The way I solved this was to add a UINavigationController. It seemed like the only way to properly solve this issue.

نصائح أخرى

Try setting the frame of the search Bar to animate up the screen when the user begins searching, that is how I solved this.

-(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);
    }];
}
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top