我正面臨一個非常奇怪的問題,我向用戶展示類別,使用水平CollectionView
的Xamarin.iOS
,我也使用MvvMCross
。問題是,當我滾動類別CollectionView
和回滾一些單元格是空的。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];
}
}
這就是我如何綁定上述collectionview單元格。
CategoryCollectionView.RegisterNibForCell(DealListCategoryCollectionCellView.Nib, DealListCategoryCollectionCellView.Key);
var categorySource = new MvxCollectionViewSource(CategoryCollectionView,DealListCategoryCollectionCellView.Key);
CategoryCollectionView.Source = categorySource;