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