0

I have a UITabBarController with 4 tabs containing identical UINavigationControllers + UITableViewControllers. Each one has a UISearchBar and UISearchDisplayController and implement all delegate methods. First I click on any tab, tap the search bar, enter text and press search. I placed a log inside the numberOfSectionsInTableView to see how the view controller is recognising the frontmost table view (for now I'm just returning zero results).

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    if (tableView == self.searchDisplayController.searchResultsTableView) {
        NSLog(@"Search Controller is the current table view");
        return 0;
    } else
        NSLog(@"Search Controller is not the current table view");

    return self.itemSections.count;
}

This time the first statement is printed in the console.

I then (without dismissing the search controller) change the tab and then straight away go back to the first tab (with the search controller). The search controller is still the frontmost view however the second log statement is printed rather than the other.

If I change:

if (tableView == self.searchDisplayController.searchResultsTableView)

to:

if (tableView == self.searchDisplayController.searchResultsTableView || self.searchDisplayController.isActive)

then the second criteria in the new if-statement allows the controller to behave the way it should. My question is why is tableView in the numberOfSectionsInTableView method not equal to self.searchDisplayController.searchResultsTableView when self.searchDisplayController is active?

sooper
  • 5,991
  • 6
  • 40
  • 65

0 Answers0