1

I have the same problem as Using becomeFirstResponder causes cancel button to not work, except that the solution doesn't work in my case.

I created a storyboard project with a Navigation controller and a Table view controller in it. I added a UISearchDisplayController to the table view and all works well until I try to access the searchDisplayController as seen below in the code snippet. I am using a section index and added UITableViewIndexSearch (or @"{search}") to the top of the section titles so that the magnifying glass shows at the beginning of the A - Z index. When I click on the section index the following function is called:

- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
  if ([title isEqualToString:UITableViewIndexSearch])
  {
    [self.searchDisplayController setActive:TRUE animated:TRUE];   // Either of these two lines
    [self.searchDisplayController.searchBar becomeFirstResponder]; // will cause the search bar cancel button to not work
    return 0;
  }
  return index - 1;
}

If I comment out both of the lines that access searchDisplayController then the search bar cancel button works as expected. If either of the two lines is not commented out in the code then the cancel button on the search bar acts as if it were not even there. Removing the becomeFirstResponder line means that I must click/touch in the search bar field to transfer focus to it, so in this case when I click on the cancel button the search bar gets focus. It's as if the cancel button is seen transparently through the search bar but can't be clicked/touched. Take those two lines of code out and the cancel button works again.

What the heck is going on?

Community
  • 1
  • 1

0 Answers0