Bug 47926 - Programatically adding a UIPickerView causes MonotouchException
Summary: Programatically adding a UIPickerView causes MonotouchException
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 10.4 (C9)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-11-25 01:22 UTC by Felix Collins
Modified: 2016-11-25 12:18 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: Yes
Last known good build: Not sure...

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:
Status:
RESOLVED ANSWERED

Description Felix Collins 2016-11-25 01:22:11 UTC
2016-11-25 14:06:53.196 testuipickerview[8364:1721535] -[UIPickerViewModel numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x17eadb80
2016-11-25 14:06:53.200 testuipickerview[8364:1721535] Xamarin.iOS: Received unhandled ObjectiveC exception: NSInvalidArgumentException -[UIPickerViewModel numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x17eadb80


Steps to reproduce:
1. Create a single page ios application in Xamarin Studio.
2. Add these three lines to the ViewDidLoad method of the ViewController.cs
  			var view = new UIPickerView();
			view.Model = new UIPickerViewModel();
			Add(view);
3. Run on ios 9.1 device (I'm running on iPad).
Comment 1 Vincent Dondain [MSFT] 2016-11-25 12:18:44 UTC
Hi,

You have to give UIPickerView a data source otherwise iOS does not know how to populate it.

The solution here is to implement IUIPickerViewDataSource, Xamarin Studio should underline it in red to help you add the required methods "GetComponentCount" and "GetRowsInComponent" (press option + space on the interface), you'll then have to return some values of your choice and finally add "view.DataSource = this;"

So with the default SingleView App template you'd get a ViewController.cs like this: https://gist.github.com/VincentDondain/b2e4803d1402451300fdcd2fb8768478