Bug 25981 - UIPickerViewModel overrides not being called
Summary: UIPickerViewModel overrides not being called
Status: CLOSED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.iOS.dll ()
Version: XI 8.6.0
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-01-13 11:42 UTC by Adam Patridge
Modified: 2015-01-16 11:56 UTC (History)
3 users (show)

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


Attachments
Screenshot of picker contents (bunch of ?s). (23.81 KB, image/png)
2015-01-13 11:42 UTC, Adam Patridge
Details


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:
CLOSED ANSWERED

Description Adam Patridge 2015-01-13 11:42:59 UTC
Created attachment 9340 [details]
Screenshot of picker contents (bunch of ?s).

Under the latest Stable Xamarin.iOS, I can't seem to get titles on a UIPickerView using a UIPickerViewModel source when the picker items are shown. Instead, it shows the proper number of items, but they all have the title of "?" (just a question mark). Also, selecting them doesn't seem to do anything.

I rigged up some simple code to reproduce the issue. I can certainly throw up the entire project, but at the very least the view controller is up on this Gist: https://gist.github.com/patridge/6c1d35292e776c08d878

Here is the UIPickerViewModel from that Gist for completeness.

> public class SomePickerViewModel : UIPickerViewModel {
> 	static readonly List<string> items = Enumerable.Range(1, 10).Select(i => "picker item " + i).ToList();
> 	public override nfloat GetRowHeight (UIPickerView pickerView, nint component)
> 	{
> 		Console.WriteLine ("GetRowHeight: {0}", component);
> 		return 50f;
> 	}
> 	public override nint GetComponentCount (UIPickerView pickerView)
> 	{
> 		Console.WriteLine ("GetComponentCount");
> 		return 1;
> 	}
> 	public override nint GetRowsInComponent (UIPickerView pickerView, nint component)
> 	{
> 		Console.WriteLine ("GetRowsInComponent");
> 		return items.Count;
> 	}
> 	public override string GetTitle (UIPickerView pickerView, nint row, nint component)
> 	{
> 		Console.WriteLine ("GetTitle: {0}:{1}", row, component);
> 		return items [(int)row]; // Never called when displaying picker.
> 	}
> 	public override void Selected (UIPickerView pickerView, nint row, nint component)
> 	{
> 		Console.WriteLine ("Selected: {0}:{1}", row, component); // Never called when item selected.
> 	}
> }

From the debugging statements in that code, it appears that some of the overridden methods are simply not called. I am also suspicious of the methods that are called and how often they are called. When that sample code is run, here is the console output.

> PickerViewFailExample[7159:1253700] GetComponentCount
> PickerViewFailExample[7159:1253700] GetComponentCount
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetComponentCount
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetComponentCount
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent
> PickerViewFailExample[7159:1253700] GetRowsInComponent

I thought it could be that I needed to offer an override for `GetAttributedTitle` instead, but adding that method with a simple call to `GetTitle` didn't resolve the issue (added now to the above Gist).

This issue occurs on emulators and physical devices (tested on iOS 6.1.6 and iOS 8.1.2).

Install details:

Xamarin Studio
Version 5.7 (build 661)
Installation UUID: 6fcde369-8230-488d-b74f-2c9b163b5a2f
Runtime:
	Mono 3.12.0 ((detached/a813491)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 312000068

Apple Developer Tools
Xcode 6.1.1 (6611)
Build 6A2008a

Xamarin.iOS
Version: 8.6.0.51 (Business Edition)
Hash: dfb682f
Branch: 
Build date: 2015-01-08 13:39:32-0500
Comment 1 Adam Patridge 2015-01-13 13:13:37 UTC
It just seems to happen when you go for a UIPickerViewModel system, but not when you bypass it. I decided to try to work around this issue with discrete UIPickerViewDataSource and UIPickerViewDelegate classes, and the bug doesn't happen in that situation. Hopefully this helps nail down the bug a little.

I'll update the original Gist in a few minutes to have a working version for comparison (or if anyone else needs a workaround to get by until it is fixed).
Comment 2 Sebastien Pouliot 2015-01-13 23:22:02 UTC
It works fine. The important thing is that, if you use the Model (which implements both the data source and the delegate), then you must assign it to the Model property (so it gets assigned to both), i.e.

			SomePickerView = new UIPickerView () {
				Model = new SomePickerViewModel(),
			};

In your sample you only assign it to the DataSource (and only those selectors ended up being called).
Comment 3 Adam Patridge 2015-01-14 10:57:57 UTC
That certainly makes sense, and thank you for noticing that issue.

I found the issue from source control history. It was previously `Source = someModel`. When I did the Unified update to its first pre-release version, that threw a compile error. I fixed it by changing to `DataSource` instead of `Model` because I didn't realize that was the new correct property.
Comment 4 Ram Chandra 2015-01-16 11:56:53 UTC
I have checked this issue issue and I observed that when I assign data source to the Model property it is working fine.

Screencast: http://www.screencast.com/t/KBW7UnYpx

This issue has been answered. Hence, I am closing this issue.