0

i´m having a tough time with UISearchDisplayController. In my scenario i have an UIView pushed onto a navgation controller. In the UIView i have an UITableView and UIToolbar. In the UITableView I´m using UISearchDisplayController.

<img></img>

The toolbar buttons are used to add additional filter options to the search. My problem is that I can´t figure out, how to add the toolbar at the bottom of the result table view of the UISearchDisplayController.

enter image description here

What is the way to go to add a toolbar to the results?

BBog
  • 3,630
  • 5
  • 33
  • 64

2 Answers2

0

I finally managed to solve my problem.

Instead of using UISearchDisplayController i only add a UISearchBar to my UITableView and replicate the behavior of UISearchDisplayController with the UISearchBarDelegate methods.

- (void)searchBar:(UISearchBar *)searchBar textDidChange:(NSString *)searchText
{
    [self setSearchText:searchText];
    [self filterCards];
}

- (void)searchBar:(UISearchBar *)searchBar selectedScopeButtonIndexDidChange:(NSInteger)selectedScope
{
    [self setScopeIndex:selectedScope];
    [self filterCards];
}

- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar
{
    // Move searchbar to table view
    [self.chapterSearchBar removeFromSuperview];
    [self.chapterTableView addSubview:[self chapterSearchBar]];

    // Show navigation controller
    [self.navigationController setNavigationBarHidden:NO animated:YES];

    // Hide scope bar an resize
    [searchBar setShowsScopeBar:NO];
    [searchBar sizeToFit];

    // Hide cancel button
    [searchBar setShowsCancelButton:NO animated:YES];

    // Resize table view
    CGRect tableViewRect = [self.chapterTableView frame];    
    tableViewRect.origin.y = 0;
    [self.chapterTableView setFrame:tableViewRect];

    // Hide keyboard
    [searchBar resignFirstResponder];
    [self setSearchText:@""];
    [self filterCards];
}

- (void)searchBarSearchButtonClicked:(UISearchBar *)searchBar
{
    [searchBar resignFirstResponder];
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar
{
    // Move searchbar to controller view
    [self.chapterSearchBar removeFromSuperview];
    [self.view addSubview:[self chapterSearchBar]];

    // Hide navigation controller
    [self.navigationController setNavigationBarHidden:YES animated:YES];

    // Show scope bar an resize
    [searchBar setShowsScopeBar:YES];
    [searchBar sizeToFit];

    // Show cancel button
    [searchBar setShowsCancelButton:YES animated:YES];

    // Resize table view
    CGRect tableViewRect = [self.chapterTableView frame];    
    tableViewRect.origin.y = 44;
    [self.chapterTableView setFrame:tableViewRect];

    return YES;
}
0

If anyone's curious how to solve this issue with still using UISearchDisplayController (cleaner probably), simply set the items of your toolbar to your view controller's toolbarItems while search is active:

self.navigationController.toolbarHidden = NO;
self.toolbarItems = optionsToolbar.items;

The UISearchDisplayController retains the view controller's toolbar according to toolbarItems, so this might already be done for you. Can be useful if the toolbar is only being used during search.

Dan
  • 133
  • 1
  • 6