Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin CollectionView中的空单元格_Xamarin_Xamarin.ios_Mvvmcross - Fatal编程技术网

Xamarin CollectionView中的空单元格

Xamarin CollectionView中的空单元格,xamarin,xamarin.ios,mvvmcross,Xamarin,Xamarin.ios,Mvvmcross,我面临一个非常奇怪的问题,我正在使用Xamarin.iOS中的水平CollectionView向用户显示类别,我也在使用MvvMCross。问题是,当我滚动类别CollectionView并向后滚动时,一些单元格是空的 这是MvxCollectionViewCell的子类的代码,在该子类中,我将值绑定到UI public partial class DealListCategoryCollectionCellView : MvxCollectionViewCell { p

我面临一个非常奇怪的问题,我正在使用
Xamarin.iOS中的水平
CollectionView
向用户显示类别,我也在使用
MvvMCross
。问题是,当我滚动类别
CollectionView
并向后滚动时,一些单元格是空的

这是
MvxCollectionViewCell
的子类的代码,在该子类中,我将值绑定到UI

public partial class DealListCategoryCollectionCellView : MvxCollectionViewCell
    {
        public static readonly UINib Nib = UINib.FromName("DealListCategoryCollectionCellView", NSBundle.MainBundle);
        public static readonly NSString Key = new NSString("CategoryCollectionViewCell");
        private FXMvxImageViewLoader _imageLoader;

        public DealListCategoryCollectionCellView(IntPtr handle) : base(handle)
        {
            _imageLoader = new FXMvxImageViewLoader(() => CategoryImageView);
            this.DelayBind(() =>
            {

                var set = this.CreateBindingSet<DealListCategoryCollectionCellView, CategoryCellViewModel>();
                set.Bind(TitleLabel).To(vm => vm.Name);
                set.Bind(_imageLoader).To(vm => vm.Slug).WithConversion("LocalImage", "icons");
                set.Apply();

            });
        }

        public static DealListCategoryCollectionCellView Create()
        {
            return (DealListCategoryCollectionCellView)Nib.Instantiate(null, null)[0];
        }
    }

这是问题的屏幕截图:

我已通过首先更改此选项修复了问题:

CategoryCollectionView.Source = categorySource;
致:

因此,当我从
Source
更改为
DataSource
时,空单元格问题得到了解决,但还有一个问题,我的tap-on-cell没有被触发。因此,我实现了如下
CollectionViewDelegate

class CategoryCollectionDelegate : UICollectionViewDelegate
    {
        DealListViewModel viewModel;
        public CategoryCollectionDelegate(DealListViewModel vm)
        {
            viewModel = vm;
        }
        public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            Category currentCategory = viewModel.Categories[indexPath.Row];
            Console.WriteLine(currentCategory.Name);
            viewModel.DoSelectCategoryCommand(currentCategory);
        }
    }
然后我就这样使用它:

CategoryCollectionView.Delegate = new CategoryCollectionDelegate(DealListViewModel);

它工作起来很有魅力:)

我首先改变了这个问题:

CategoryCollectionView.Source = categorySource;
致:

因此,当我从
Source
更改为
DataSource
时,空单元格问题得到了解决,但还有一个问题,我的tap-on-cell没有被触发。因此,我实现了如下
CollectionViewDelegate

class CategoryCollectionDelegate : UICollectionViewDelegate
    {
        DealListViewModel viewModel;
        public CategoryCollectionDelegate(DealListViewModel vm)
        {
            viewModel = vm;
        }
        public override void ItemSelected(UICollectionView collectionView, NSIndexPath indexPath)
        {
            Category currentCategory = viewModel.Categories[indexPath.Row];
            Console.WriteLine(currentCategory.Name);
            viewModel.DoSelectCategoryCommand(currentCategory);
        }
    }
然后我就这样使用它:

CategoryCollectionView.Delegate = new CategoryCollectionDelegate(DealListViewModel);

它的工作方式很有魅力:)

我的解决方案是覆盖CollectionViewSource中的CellDisplayingEnded方法。正如您在这里看到的,CellDisplayingEnded方法中有一些注释代码,可能在某些版本的mvvmcross中没有注释,dataContext设置为null。

我的解决方案是覆盖CollectionViewSource中的CellDisplayingEnded方法。正如您在这里看到的,CellDisplayingEnded方法中有一些注释代码,可能在某些版本的mvvmcross中没有注释,并且dataContext设置为null