Xamarin.iOS UITableView没有通过ReloadData更新()
问题描述:
我有UITableView与自定义单元格。代码单元:Xamarin.iOS UITableView没有通过ReloadData更新()
public partial class SaleTableViewCell : MvxTableViewCell
{
public static readonly NSString Key = new NSString("SaleTableViewCell");
public static readonly UINib Nib = UINib.FromName("SaleTableViewCell", NSBundle.MainBundle);
public SaleTableViewCell(IntPtr handle)
: base(handle)
{
this.DelayBind(() =>
{
var set = this.CreateBindingSet<SaleTableViewCell, SaleItem>();
set.Bind(IdLabel).To(vm => vm.ProductKey);
set.Bind(NameLabel).To(vm => vm.Description);
set.Bind(QuantityLabel).To(vm => vm.Quantity);
set.Bind(PriceLabel).To(vm => vm.Price);
set.Bind(DiscountLabel).To(vm => vm.DiscountAmount);
set.Bind(TotalLabel).To(vm => vm.Total);
set.Apply();
});
}
public static SaleTableViewCell Create()
{
return (SaleTableViewCell)Nib.Instantiate(null, null)[0];
}
}
我使用MvxSimpleTableViewSource:
var source = new MvxSimpleTableViewSource(TableView, SaleTableViewCell.Key, SaleTableViewCell.Key);
TableView.Source = source;
但是,当我试图改变SaleItem的任何属性(例如数量)我的TableView ISN即使我直接致电TableView.ReloadData();
我做错了什么?
答
SaleItem
需要实现INotifyPropertyChanged。 然后你可以改变它的属性,你会看到表单元格中的结果。
最简单的方法是使用这个nuget:https://github.com/Fody/PropertyChanged,但你也可以自己编写实现。
发布您的SaleItem类的代码以及与您的TableView关联的ViewModel。一般来说,一旦你更新了一个单元格的属性,你需要在绑定到你的ListView的ObservableCollection上调用RaisePropertyChanged来重新加载数据。 – pnavk