2016-08-24 13 views
1

別のUICollectionViewの各セルにUICollectionViewがあります。外側のUICollectionViewは垂直方向にスクロールしますが、垂直方向のUICollectionViewからの各セル内のUICollectionViewはスクロールしません。その理由はわかりません。UICollectionView内のUICollectionViewはスクロールしません。

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のための私のセルである:

は、ここに私のViewControllerです。

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); 

    } 




} 
} 

次は、2番目の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; 
    } 

} 
} 

レイアウトは私の望むように見えますが、2番目のUICollectionViewはスクロールしません。

enter image description here

答えて

0

ColTwoはContentViewなくBackgroundViewに添加されるべきです。このように - ContentView.AddSubview(ColTwo)

関連する問題