在我的xamarin ios项目中,我在UICollectionView单元格中填充图像。它能够删除或旋转图像。我想知道有什么方法可以在源更改后立即更新单元格吗?
细胞:
public class MyCellCollectionViewSource: MvxCollectionViewSource
{
public ObservableCollection < Animal > animals;
ViewModel1 vm;
public MyCellCollectionViewSource(ViewModel1 vm, int noOfImages) : base(collectionView)
{
this.vm = vm;
animals = new ObservableCollection < Animal > ();
for (int i = 0; i < noOfImages; i++) {
//animals.Add(i);
switch (i) {
case 0:
animals.Add(new Animal() {
indexCell = 1,
image = vm.Photo1
});
break;
case 1:
animals.Add(new Animal() {
indexCell = 2,
image = vm.Photo2
});
break;
case 2:
animals.Add(new Animal() {
indexCell = 3,
image = vm.Photo3
});
break;
case 3:
animals.Add(new Animal() {
indexCell = 4,
image = vm.Photo4
});
break;
case 4:
animals.Add(new Animal() {
indexCell = 5,
image = vm.Photo5
});
break;
case 5:
animals.Add(new Animal() {
indexCell = 1,
image = newPostDetailViewModel.Photo1
});
break;
}
}
public override UICollectionViewCell GetCell(UICollectionView collectionView, NSIndexPath indexPath)
{
var cell = (MyCell) collectionView.DequeueReusableCell(animalCellId, indexPath);
Cell.PopulateCell(indexPath.Row);
cell.Closebtn.TouchUpInside += delegate {
MyCellCollectionViewSource source = collectionView.DataSource as MyCellCollectionViewSource;
vm.DeleteCommand.Execute(indexPath.Row);
ReloadData();
};
cell.UserPostbtn.TouchUpInside += delegate {
MyCellCollectionViewSource source = collectioview.DataSource as MyCellCollectionViewSource;
newPostDetailViewModel.EditPhotoCommand.Execute(indexPath.Row);
ReloadData();
};
}
}
单元格具有CloseBtn和UserPostBtn。
当我点击CloseBtn时,我可以在我的observableCollection&#39;动物&#39;该单元格被删除。但是我看不到它们反映在我的馆藏视图上,如果我再回来重新加载整个页面,那么我可以看到我的变化。
同样,如果我点击UserPostBtn,它会旋转图像,但那些更改不会动态反映,我必须返回并重新加载重新加载整个页面以更新单元格。