2

I have a UIViewController that has a UICollectionView added as a subview in the viewDidLoad. I am using a UICollectionViewFlowLayout and have created a custom MvxCollectionViewSource to manage the cells.

I provide the cell information in the constructor of the layout object which does not make it flexible for device and orientation changes.

UICollectionViewLayout layout = new UICollectionViewFlowLayout () {ItemSize = new SizeF (354, 150),
            ScrollDirection = UICollectionViewScrollDirection.Vertical
        };

Allocating my UICollectionView in the ViewDidLoad method.

CollectionView = new UICollectionView (this.View.Bounds, layout);
        CollectionView.Delegate = new CustomViewDelegate();
        CollectionView.RegisterClassForCell (typeof(ProjectCollectionCell), ProjectCollectionCell.Key);
        CollectionView.Source = new ProjectCollectionSource (CollectionView, this,ProjectCollectionCell.Key);
        CollectionView.BackgroundColor = UIColor.Clear;
        //          CollectionView.RegisterClassForSupplementaryView (typeof(Header), UICollectionElementKindSection.Header, headerId);
        CollectionView.AllowsMultipleSelection = true;
        this.View.AddSubview (CollectionView);

Now the ProjectCollectionSource is my custom source and have created a UICollectionViewDelegateFlowLayout as mentioned here.

The UICollectionViewDelegateFlowLayout is as below but it never gets called.

class CustomViewDelegate: UICollectionViewDelegateFlowLayout
    {

        public override CoreGraphics.CGSize GetSizeForItem (UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath)
        {
            return new CoreGraphics.CGSize (100, 100);
        }
    }
Community
  • 1
  • 1
B K
  • 1,554
  • 3
  • 19
  • 40
  • 1
    I've got a small demo for collection view on Github - maybe it helps you to identify the problem? https://github.com/Krumelur/QuickAndDirtyCollViewDemo – Krumelur May 18 '15 at 07:48
  • 1
    @Krumelur +1 You demo app did help me with my problem. I was setting my custom source to the UICollectionView "Source" but when I set it to the collectionview "data source", it started working. – B K May 20 '15 at 04:17

0 Answers0