Bug 37448 - UITableView ignoring DataSource and Delegate
Summary: UITableView ignoring DataSource and Delegate
Status: CONFIRMED
Alias: None
Product: Xamarin Studio
Classification: Desktop
Component: iOS Designer ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: master
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-01-06 15:05 UTC by Kevin Mullins
Modified: 2017-07-19 22:20 UTC (History)
6 users (show)

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


Attachments
Example app. Comment out the code in the TODO section of the UITableViewController to see the issue (327.61 KB, application/zip)
2016-01-06 15:05 UTC, Kevin Mullins
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 for Bug 37448 on Developer Community or GitHub if you have new information to add and do not yet see a matching new report.

If the latest results still closely match this report, you can use the original description:

  • Export the original title and description: Developer Community HTML or GitHub Markdown
  • Copy the title and description into the new report. Adjust them to be up-to-date if needed.
  • Add your new information.

In special cases on GitHub you might also want the comments: GitHub Markdown with public comments

Related Links:
Status:
CONFIRMED

Description Kevin Mullins 2016-01-06 15:05:07 UTC
Created attachment 14468 [details]
Example app. Comment out the code in the TODO section of the UITableViewController to see the issue

In the current version of Xamarin.iOS, if I attach a fully formed DataSource (`UITableViewDataSource`) and Delegate (`UITableViewDelegate`) to the TableView (`UITableView`) property of a `UITableViewController` both the DataSource and the Delegate are being ignored or overridden by the extension methods assigned to the binding of `UITableViewController` (for example `RowsInSection`).

This was not the case in previous version of Xamarin.iOS and will break existing iOS app that use Table Views with Datasource and Delegates instead of the Source property. This is also invalid behavior, as Datasource and Delegate should be enough to fully support a Table View.

As a temporary work around, if you override the extension methods on the `UITableViewController`, and point back to the Datasource on the TableView. Example:

public partial class GrowRowTableViewController : UITableViewController
	{
		#region Computed Properties
		public GrowRowTableDataSource DataSource {
			get { return TableView.DataSource as GrowRowTableDataSource; }
		}

		public GrowRowTableDelegate TableDelegate {
			get { return TableView.Delegate as GrowRowTableDelegate; }
		}
		#endregion

		#region Constructors
		public GrowRowTableViewController (IntPtr handle) : base (handle)
		{
		}
		#endregion

		#region Override Methods
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

		}

		public override void ViewWillAppear (bool animated)
		{
			base.ViewWillAppear (animated);

			// Initialize table
			TableView.DataSource = new GrowRowTableDataSource(this);
			TableView.Delegate = new GrowRowTableDelegate (this);
			TableView.EstimatedRowHeight = 40f;
			TableView.ReloadData ();
		}
			
		// ---------------------------------------------------------------------------------------
		// TODO: I shouldn't need override these two methods, but without them the Datasource and 
		// Delegate aren't being called. This wasn't required before.
		// ---------------------------------------------------------------------------------------
		public override nint NumberOfSections (UITableView tableView)
		{
			return DataSource.NumberOfSections(tableView);
		}

		public override nint RowsInSection (UITableView tableView, nint section)
		{
			return DataSource.RowsInSection(tableView, section);
		}
		// ---------------------------------------------------------------------------------------
		#endregion
	}
Comment 1 Rolf Bjarne Kvinge [MSFT] 2016-01-07 14:23:47 UTC
This is because somehow the GrowRowTableView.designer.cs has this code:

> [Register ("GrowRowTableView")]
> partial class GrowRowTableView
> {
>	[Outlet]
>	[GeneratedCode ("iOS Designer", "1.0")]
>	GrowRowTableViewController dataSource { get; set; }
>
>	[Outlet]
>	[GeneratedCode ("iOS Designer", "1.0")]
>	GrowRowTableViewController @delegate { get; set; }

which is just wrong.

Reassigning to iOS Designer, since I don't know if this is the designer that did something wrong, or something else happened.
Comment 2 Will Smith 2017-07-19 22:20:26 UTC
Thanks so much for taking the time to submit this report! I can confirm using the latest Visual Studio 2017 for Mac Preview version 7.1 I am able to reproduce this issue. Marking this report as CONFIRMED.