1
我在另一個UICollectionView的每個單元中有一個UICollectionView。外部UICollectionView滾動垂直,但垂直UICollectionView每個單元格內的UICollectionView不會滾動,我不知道爲什麼。UICollectionView內的UICollectionView不會滾動
這裏是我的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;
}
}
}
這裏是我的第一個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);
}
}
}
這是我的第二個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;
}
}
}
佈局看起來就像我想要的那樣,但第二個UICollectionView只是不會滾動。