是否可以在UICollectionView中混合使用多个NIB?

时间:2017-04-27 13:29:44

标签: xamarin.ios uicollectionview mvvmcross nib

我必须使用3种不同类型的块创建一个视图,例如iTunes Appstore:一个用于图像(ImageBlock),另一个用于object1(Type1List)列表,第三个用于object2(Type2List)列表。

我有三个功能的MvxCollectionViewCells,但是我需要从这三个中创建一个UICollectionView。我有这些列表(项目)的列表。单个列表(Item)有一个名为“type”的值,它是一个整数值1,2或3.我必须得到每个Item的这个整数值,并确定我想要用于这个特定单元格的NIB。

//Collection = UICollectionView
//ViewModel.Items = MvxObservableCollection<Item>

public override void ViewDidLoad()
{
    base.ViewDidLoad();

    var set = this.CreateBindingSet<View, ViewModel>();

    // NIBs for types 1, 2 and 3 respectively
    Collection.RegisterNibForCell(Type1List.Nib, Type1List.Key);
    Collection.RegisterNibForCell(Type2List.Nib, Type2List.Key);
    Collection.RegisterNibForCell(ImageBlock.Nib, ImageBlock.Key);

    // This shows all items of type 1 correctly, and others using type 1 XIB with no contents
    Source = new MvxCollectionViewSource(Collection, Type1List.Key);

    // This gives a Null Reference Exception if used in place of the previous one
    //Source = new MvxCollectionViewSource(Collection);

    set.Bind(Source)
        .To(vm => vm.Items);

    // This takes the items and calculates the height for Collection in this View
    // All types will differ in size
    set.Bind(CollectionHeight)
        .For(v => v.Constant)
        .To(vm => vm.Items)
        .WithConversion("IosCollectionHeight", Collection);

    Collection.Source = Source;

    // Set to 200 for now to see the cells
    // TODO: set a working variable size
    (Collection.CollectionViewLayout as UICollectionViewFlowLayout).ItemSize = new CoreGraphics.CGSize(UIScreen.MainScreen.Bounds.Width, 200);
    //(Collection.CollectionViewLayout as UICollectionViewFlowLayout).EstimatedItemSize = new CoreGraphics.CGSize(UIScreen.MainScreen.Bounds.Width, 100);

    set.Apply();

    Collection.ReloadData();
}

所以我目前有两个问题:

  1. 我不知道如何为我的UICollectionView
  2. 按类型使用不同的NIB
  3. 我不知道如何按类型
  4. 调整单元格大小

    所有三个单元NIB都经过测试并按预期工作,但此CollectionView存在问题。

    -Pasketi

0 个答案:

没有答案
相关问题