I have a UISearchController that is dismissed when the user clicks the cancel button. After the user clicks the cancel button, I want the UISearchController to be dismissed first then the showNewTableData method needs to be called. Here is the code that I am using that works.
-(void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
dispatch_async(dispatch_get_main_queue(), ^{
[self showNewTableData];
});
}
-(void)showNewTableData {
if (self.searchController.active && self.searchController.searchBar.text.length > 0) {
// show search data
} else {
// show non search data
}
}
Using dispatch_async seems to accomplish my requirements very well, but not sure if this is a good idea. If I don’t use dispatch_async, I will end up showing search data because the search bar hasn’t finished clearing text and it is still active. Any suggestions are appreciated.