title: iOS UISearchController: Wait until UISearchController is dismissed after canceling search
body: <p>I have a <code>UISearchController</code> that is dismissed when the user clicks the cancel button. After the user clicks the cancel button, I want the <code>UISearchController</code> to be dismissed first then the showNewTableData method needs to be called. Here is the code that I am using that works.</p>
  
  <pre><code>- (void)searchBarCancelButtonClicked:(UISearchBar *)searchBar {
      dispatch_async(dispatch_get_main_queue(), ^{
          [self showNewTableData];
      });
  }
  
  - (void)showNewTableData {
        if (self.searchController.active &amp;&amp; self.searchController.searchBar.text.length &gt; 0) {
           // show search data
        } else {
           // show non search data
        }
      }
  </code></pre>
  
  <p>Using <code>dispatch_async</code> seems to accomplish my requirements very well, but not sure if this is a good idea. If I don't use <code>dispatch_async</code>, 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.</p>