So in - (void)searchBarCancelButtonClicked:(UISearchBar *)sBar, I need to be able to hide the cancel button after the user has tapped cancel. I also need to reset the index titles on the right so they show again. I previously hid them by setting them to nil in searchBarShouldBeginEditing (which I added to SCTableViewModel). However, in order to be able to show the index titles again, you need to tell the table view to reloadData. This is already being done in searchBarCancelButtonClicked. But it's doing it before the callback to the delegate method. Unfortunately this means that I also must tell the table view to reloadData. This causes a delay since when you tap the cancel button, you are effectively reloading the table twice.
Can the delegate callback method be put at the beginning of searchBarCancelButtonClicked instead of the end?
So I would like to see:
- (void)searchBarCancelButtonClicked:(UISearchBar *)sBar
{
if([self.delegate conformsToProtocol:@protocol(SCTableViewModelDelegate)]
&& [self.delegate respondsToSelector:@selector(tableViewModelSearchBarCancelButtonClicked:)])
{
[self.delegate tableViewModelSearchBarCancelButtonClicked:self];
}
[self.searchBar resignFirstResponder];
self.searchBar.text = nil;
[filteredArray release];
filteredArray = nil;
[self generateSections];
[self.modeledTableView reloadData];
}
Instead of:
- (void)searchBarCancelButtonClicked:(UISearchBar *)sBar
{
[self.searchBar resignFirstResponder];
self.searchBar.text = nil;
[filteredArray release];
filteredArray = nil;
[self generateSections];
[self.modeledTableView reloadData];
if([self.delegate conformsToProtocol:@protocol(SCTableViewModelDelegate)]
&& [self.delegate respondsToSelector:@selector(tableViewModelSearchBarCancelButtonClicked:)])
{
[self.delegate tableViewModelSearchBarCancelButtonClicked:self];
}
}
Thanks!
Brendan