2

MvxCollectionViewController 内からヘッダー ビューとフッター ビューを提供しようとしていますが、問題が発生しています。通常、UICollectionViewController では、次のように GetViewForSupplementaryElement メソッドをオーバーライドします。

public override UICollectionReusableView GetViewForSupplementaryElement (UICollectionView collectionView, NSString elementKind, NSIndexPath indexPath)
{
    var someHeaderOrFooterView = (HeaderOrFooterView) collectionView.DequeueReusableSupplementaryView (elementKind, elementId, indexPath);
    return someHeaderOrFooterView;
}

MvxCollectionViewControllers は、UICollectionViewController のように GetViewForSupplementaryElement メソッドへのデリゲート コールバックを取得していないようです。

MvxCollectionViewController を使用して CollectionView のヘッダーとフッターを指定する別の方法はありますか?

4

3 に答える 3

6

標準的な手順が機能するはずです (ここで機能します...):

  1. レイアウトのヘッダーのサイズを指定します

        HeaderReferenceSize = new System.Drawing.SizeF(100, 100),
    
  2. ヘッダーのクラスを実装する

    public class Header : UICollectionReusableView
    {
        UILabel label;
    
        public string Text
        {
            get { return label.Text; }
            set { label.Text = value; SetNeedsDisplay(); }
        }
    
        [Export("initWithFrame:")]
        public Header(System.Drawing.RectangleF frame)
            : base(frame)
        {
            label = new UILabel() { Frame = new System.Drawing.RectangleF(0, 0, 300, 50), BackgroundColor = UIColor.Yellow };
            AddSubview(label);
        }
    }
    
  3. そのクラスを登録する

       CollectionView.RegisterClassForSupplementaryView(typeof(Header), UICollectionElementKindSection.Header, headerId); 
    
  4. GetViewForSupplementaryElement を実装する

    public override UICollectionReusableView GetViewForSupplementaryElement(UICollectionView collectionView, NSString elementKind, NSIndexPath indexPath)
    {
        var headerView = (Header)collectionView.DequeueReusableSupplementaryView(elementKind, headerId, indexPath);
        headerView.Text = "Supplementary View";
        return headerView;
    }
    

ここでこれらの手順をテストしたところ、サンプル アプリで動作します ( https://github.com/slodge/NPlus1DaysOfMvvmCross/tree/master/N-11-KittenView_Collectionsに基づく)。


余談>バインド可能な補足ビューを提供する未解決の問題があります-https ://github.com/slodge/MvvmCross/issues/339-しかし、この問題は基本的なコレクションビュー操作には影響しません。

于 2013-09-18T06:48:01.447 に答える
0

私は MvvmCross でも同じ問題を抱えていました。MvxCollectionViewSource クラスをサブクラス化し、GetViewForSupplementaryElement メソッドをオーバーライドすることで解決できました。

public class MyCollectionViewSource: MvxCollectionViewSource
{
    public TimelineSource(UICollectionView collectionView, NSString defaultCellIdentifier) : base(collectionView, defaultCellIdentifier)
    {
    }

    public override UICollectionReusableView GetViewForSupplementaryElement(UICollectionView collectionView, NSString elementKind, NSIndexPath indexPath)
    {
        var headerView = (MyHeader)collectionView.DequeueReusableSupplementaryView(elementKind, MyHeader.Key, indexPath);
        headerView.Text = "Supplementary View";
        return headerView;
    }
}
于 2013-11-24T22:01:59.293 に答える