Bug 2746 - Unrecognized Selector when creating an asynchronous UISearchBar
Summary: Unrecognized Selector when creating an asynchronous UISearchBar
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Sebastien Pouliot
Depends on:
Reported: 2012-01-05 10:07 UTC by Jonathan Peppers
Modified: 2012-01-12 09:50 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

MonoTouch project repoducing the issue (13.43 KB, application/x-zip-compressed)
2012-01-05 10:07 UTC, Jonathan Peppers

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Jonathan Peppers 2012-01-05 10:07:46 UTC
Created attachment 1128 [details]
MonoTouch project repoducing the issue

See question here on stackoverflow: http://stackoverflow.com/questions/8738013/monotouch-asynchronous-uisearchbar

Basically I'm getting this crash when creating an asynchronous UISearchBar:

2012-01-04 23:05:11.589 myApp[98047:2407] -[MainController tableView:numberOfRowsInSection:]: unrecognized selector sent to instance 0xb0ea840

  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 attached a repro.

To reproduce, search something, then hit cancel or select a search.  Search again, after typing the first letter, the crash occurs.
Comment 1 Jonathan Peppers 2012-01-06 21:59:53 UTC
Discovered workaround:

 - override `WillBeginSearch` in `UISearchDisplayDelegate`
 - set `_searchController.SearchResultsTableView.Source` to null
 - when you have results to display, set `_searchController.SearchResultsTableView.Source` to the table view source

Does this still seem to be a bug?
Comment 2 Sebastien Pouliot 2012-01-10 14:27:28 UTC
Thanks for providing the test case. I can duplicate the issue and will look into it.
Comment 3 Sebastien Pouliot 2012-01-12 08:50:57 UTC
A simpler workaround is adding:

					_searchController.SearchResultsSource = _tableSource;

before the line:

					_searchController.SearchResultsTableView.ReloadData ();

It looks like the managed code knows the _tableSource (it's there while debugging) but the objectiveC side does not (anymore). I'll keep digging inside this.
Comment 4 Sebastien Pouliot 2012-01-12 09:50:07 UTC
This is not a binding bug (I checked them to be sure). In ViewDidLoad replace

			SearchDisplayController.SearchResultsTableView.Source = _tableSource;


			SearchDisplayController.SearchResultsSource = _tableSource;

and this will fix your issue. It's weird (and badly documented IMO) but accessing the SearchResultsTableView.Source seems to mess with the internal controller state (it has it's own stuff).