title: MonoTouch - Asynchronous UISearchBar
body: <p>I have an asynchronous UISearchBar setup as follows:</p>
  
  <ul>
  <li>Inherit UISearchDisplayDelegate &amp; set it up for <code>myController.SearchDisplayController.Delegate</code></li>
  <li>Override <code>ShouldReloadForSearchString</code> -> start a new thread calling a web service and return false to not reload the <code>UITableView</code></li>
  <li>Web service completes in background -> call <code>BeginInvokeOnMainThread()</code></li>
  <li>Reload tableview via <code>myController.SearchDisplayController.SearchResultsTableView.ReloadData()</code></li>
  </ul>
  
  <p>Everything works on the first search I make, I can backspace or type and see new results pop in asynchronously.</p>
  
  <p>If I complete the search or cancel it, then try again, the call to ReloadData() causes the following crash:</p>
  
  <pre><code>2012-01-04 23:05:11.589 myApp[98047:2407] -[MainController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb0ea840
  Stacktrace:
  
    at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication.UIApplicationMain (int,string[],intptr,intptr) &lt;IL 0x0009f, 0xffffffff&gt;
    at MonoTouch.UIKit.UIApplication.Main (string[],string,string) [0x00042] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:29
    at MyApp.Application.Main (string[]) [0x00000] in /Users/jonathanpeppers/Projects/MyApp/Main.cs:13
    at (wrapper runtime-invoke) &lt;Module&gt;.runtime_invoke_void_object (object,intptr,intptr,intptr) &lt;IL 0x00050, 0xffffffff&gt;
  </code></pre>
  
  <p>I don't dispose of anything, and am keeping all my delegates in member variables to prevent GC issues.  Every background thread seems to be calling <code>BeginInvokeOnMainThread()</code> properly as well.</p>
  
  <p>Is this most likely a bug in MonoTouch?  If this is likely, I can create a repro.</p>
  
  <p>Otherwise, let me know if I'm going about this wrong.</p>