2016-07-05 71 views
0

我有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();

我做錯了什麼?

+0

發佈您的SaleItem類的代碼以及與您的TableView關聯的ViewModel。一般來說,一旦你更新了一個單元格的屬性,你需要在綁定到你的ListView的ObservableCollection上調用RaisePropertyChanged來重新加載數據。 – pnavk

回答

0

SaleItem需要實現INotifyPropertyChanged。 然後你可以改變它的屬性,你會看到表單元格中的結果。

最簡單的方法是使用這個nuget:https://github.com/Fody/PropertyChanged,但你也可以自己編寫實現。