c# scroll xamarin.ios uicollectionview

c# - UICollectionView dentro de UICollectionView no se desplazará



scroll xamarin.ios (1)

El ColTwo se debe agregar a ContentView y no a BackgroundView. Me gusta esto - ContentView.AddSubview (ColTwo)

Tengo un UICollectionView en cada celda de otro UICollectionView. El UICollectionView externo se desplaza verticalmente, pero el UICollectionView dentro de cada celda del UICollectionView vertical no se desplazará, y no tengo ni idea de por qué.

Aquí está mi ViewController:

using System; using Foundation; using UIKit; namespace ColInColTest { public partial class ViewController : UIViewController, IUICollectionViewSource, IUICollectionViewDelegate { UICollectionViewFlowLayout LayoutOne; UICollectionView ColOne; protected ViewController(IntPtr handle) : base(handle) { } public override void ViewDidLoad() { base.ViewDidLoad(); // Perform any additional setup after loading the view, typically from a nib. LayoutOne = new UICollectionViewFlowLayout(); LayoutOne.ScrollDirection = UICollectionViewScrollDirection.Vertical; LayoutOne.SectionInset = new UIEdgeInsets(0, 0, 0, 0); LayoutOne.ItemSize = new CoreGraphics.CGSize(View.Bounds.Width, 100); ColOne = new UICollectionView(CoreGraphics.CGRect.Empty, LayoutOne); ColOne.Frame = new CoreGraphics.CGRect(0, 0, View.Bounds.Width, View.Bounds.Height); ColOne.BackgroundColor = UIColor.Red; ColOne.Delegate = this; ColOne.DataSource = this; ColOne.RegisterClassForCell(typeof(CellOne), "cell1"); View.AddSubview(ColOne); } public override void DidReceiveMemoryWarning() { base.DidReceiveMemoryWarning(); // Release any cached data, images, etc that aren''t in use. } [Export("numberOfSectionsInCollectionView:")] public nint NumberOfSections(UICollectionView collectionView) { return 1; } public nint GetItemsCount(UICollectionView collectionView, nint section) { return 10; } public UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) { var cell = (CellOne)collectionView.DequeueReusableCell("cell1", indexPath); return cell; } }

}

Aquí está mi celda para el primer UICollectionView.

using System; using CoreGraphics; using Foundation; using UIKit; namespace ColInColTest { public partial class CellOne : UICollectionViewCell { UICollectionViewFlowLayout LayoutTwo; UICollectionView ColTwo; [Export("initWithFrame:")] public CellOne(CGRect frame) : base(frame) { BackgroundView = new UIView { BackgroundColor = UIColor.Orange }; LayoutTwo = new UICollectionViewFlowLayout(); LayoutTwo.ScrollDirection = UICollectionViewScrollDirection.Horizontal; LayoutTwo.SectionInset = new UIEdgeInsets(0, 0, 0, 0); LayoutTwo.ItemSize = new CoreGraphics.CGSize(100, this.Bounds.Height); ColTwo = new UICollectionView(CoreGraphics.CGRect.Empty, LayoutTwo); ColTwo.Frame = new CoreGraphics.CGRect(0, 0, BackgroundView.Bounds.Width, BackgroundView.Bounds.Height); ColTwo.BackgroundColor = UIColor.White; //ColTwo.Delegate = this; ColTwo.DataSource = new CellTwoSource(); ColTwo.ScrollEnabled = true; ColTwo.RegisterClassForCell(typeof(CellTwo), "cell2"); BackgroundView.AddSubview(ColTwo); } } }

Aquí está mi subclase para el origen de datos del segundo UICollectionView.

using System; using Foundation; using UIKit; namespace ColInColTest { public partial class CellTwoSource : UICollectionViewSource { public override nint NumberOfSections(UICollectionView collectionView) { return 1; } public override nint GetItemsCount(UICollectionView collectionView, nint section) { return 20; } public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath) { var cell = (CellTwo)collectionView.DequeueReusableCell("cell2", indexPath); return cell; } } }

El diseño se ve exactamente como yo quiero, pero el segundo UICollectionView simplemente no se desplazará.