0

我们已经设置了 collectionviewSource 和 collectionview,但是在滚动时遇到了性能问题。我们目前这样管理单元格:

    public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
    {
        var to = base.GetCell(collectionView, indexPath) as AnimalCell;
        to.SetParentLocation(_parent);
        return to;
    }

我的问题是这是否管理基类中的出队?

如果不是,最好的方法是使用标准出队

    public override UICollectionViewCell GetCell (UICollectionView collectionView, MonoTouch.Foundation.NSIndexPath indexPath)
    {
        var animalCell = (AnimalCell)collectionView.DequeueReusableCell (animalCellId, indexPath);

        var animal = animals [indexPath.Row];
        animalCell.Image = animal.Image;
        return animalCell;
    }

当我尝试使用单元格时,更改为上述代码会导致它崩溃。我是否需要更改我的 Cell 类或 collectionview 的设置方式?

4

1 回答 1

1

我的问题是这是否管理基类中的出队?

是的,默认的 MvxCollectionViewSource 使用这种方法:

    protected virtual UICollectionViewCell GetOrCreateCellFor(UICollectionView collectionView, NSIndexPath indexPath,
                                                              object item)
    {
        return (UICollectionViewCell) collectionView.DequeueReusableCell(DefaultCellIdentifier, indexPath);
    }

来自https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxBaseCollectionViewSource.cs#L55

所以无论是什么导致了性能问题,它可能不是单元重用(对不起,这可能没有多大帮助 - 但至少它排除了一个!)

于 2013-09-20T16:09:30.150 回答