Bug 36790 - CollectionView SelectItem doesn't select cell
Summary: CollectionView SelectItem doesn't select cell
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.TVOS.dll ()
Version: XI 9.3 (xcode 7.1 previews)
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2015-12-09 19:33 UTC by Vincent Roggero
Modified: 2015-12-14 15:37 UTC (History)
3 users (show)

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


Attachments
Sample app showing issue (1.96 MB, application/zip)
2015-12-10 14:43 UTC, Vincent Roggero
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:
RESOLVED ANSWERED

Description Vincent Roggero 2015-12-09 19:33:01 UTC
public class MyCollectionVC : UICollectionViewController 
{
   public PictureCollectionView Collection {
	get { return CollectionView as PictureCollectionView; }
	set { CollectionView = value; }
		}
   ViewDidLoad()
   {
      Collection.Source.PopulatePictures();
      Collection.ReloadData();

      Collection.SelectItem(NSIndexPath.FromItemSection(2, 0), true, UICollectionViewScrollPosition.Left);
    }
}

I've tried added SelectItem to ViewWillAppear, ViewDidAppear with no luck.
Comment 1 Sebastien Pouliot 2015-12-10 01:48:45 UTC
We need a full, self-contained, test case to look into this.
Comment 2 Vincent Roggero 2015-12-10 14:43:56 UTC
Created attachment 14221 [details]
Sample app showing issue
Comment 3 Sebastien Pouliot 2015-12-14 15:37:41 UTC
As stated in Apple documentation [1] the call to `SelectItem` does not call your delegate, which does the job you want.

You also need to call this at the right point in the VC life cycle. Your sample used AwakeFromNib, but at that stage the cell contents are not loaded.

The following code in CityCollectionViewController.cs does what you need:

	public override void ViewDidAppear (bool animated)
	{
		base.ViewDidAppear (animated);
		var i = NSIndexPath.FromItemSection (5, 0);
		CollectionView.SelectItem (i, true, UICollectionViewScrollPosition.CenteredHorizontally);
		CollectionView.Delegate.ItemSelected (CollectionView, i);
	}


[1] This method does not cause any selection-related delegate methods to be called.