2014-12-04 96 views
0

我想爲我的UICollectionView中的每個單元具有不同的高度。所以我重寫GetSizeForItem方法在UICollectionViewDelegateFlowLayout這樣的:GetSizeForItem不觸發

public class MyCollectionViewDelegateFlowLayout : UICollectionViewDelegateFlowLayout 
{ 
    public override CGSize GetSizeForItem(UICollectionView collectionView, UICollectionViewLayout layout, NSIndexPath indexPath) 
    { 
     // TODO custom height logic 
     return new SizeF(100, 100); 
    } 
} 

這是我如何創建UICollectionView並使用自定義的委託類:

var flowLayout = new UICollectionViewFlowLayout() 
     { 
      ItemSize = new SizeF(320, 80), 
      ScrollDirection = UICollectionViewScrollDirection.Vertical, 
      MinimumLineSpacing = 0, 
      MinimumInteritemSpacing = 0, 
      SectionInset = new UIEdgeInsets(UIScreen.MainScreen.ApplicationFrame.Height - 100, 0, 0, 0) 
     }; 

     var collectionView = new UICollectionView(UIScreen.MainScreen.ApplicationFrame, flowLayout); 
     collectionView.Delegate = new MyCollectionViewDelegateFlowLayout();    

     collectionView.RegisterNibForCell(MyCollectionCell.Nib, MyCollectionCell.Key); 
     var source = new MvxCollectionViewSource(collectionView, MyCollectionCell.Key); 
     collectionView.Source = source; 

的問題是,GetSizeForItem方法永遠不會觸發。任何想法如何解決這個問題?

回答

1

從Xamarin的論壇here,它看起來像你不能同時使用DelegateSource