I have an asynchronous UISearchBar setup as follows:
- Inherit UISearchDisplayDelegate & set it up for
myController.SearchDisplayController.Delegate - Override
ShouldReloadForSearchString-> start a new thread calling a web service and return false to not reload theUITableView - Web service completes in background -> call
BeginInvokeOnMainThread() - Reload tableview via
myController.SearchDisplayController.SearchResultsTableView.ReloadData()
Everything works on the first search I make, I can backspace or type and see new results pop in asynchronously.
If I complete the search or cancel it, then try again, the call to ReloadData() causes the following crash:
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) <IL 0x0009f, 0xffffffff>
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) <Module>.runtime_invoke_void_object (object,intptr,intptr,intptr) <IL 0x00050, 0xffffffff>
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 BeginInvokeOnMainThread() properly as well.
Is this most likely a bug in MonoTouch? If this is likely, I can create a repro.
Otherwise, let me know if I’m going about this wrong.
This is not a binding bug (I checked them to be sure). The data source should be set on the
UISearchDisplayController, not on the table view (e.g.SearchDisplayController.SearchResultsTableView).IOW replace:
with:
This will ensure the internal state of
UISearchDisplayControlleris updated properly between uses.