2014-04-11 73 views
0

我看到使用MVVMCross模板數據綁定的精彩實例。不過,我有複雜的數據源,設置單元格UI類型可以根據當前正在加載的集合中的項目的性質GetCell(IOS &安卓):MVVMCross定製細胞結合

 public override UITableViewCell GetCell (UITableView tableView, MonoTouch.Foundation.NSIndexPath indexPath) 
    { 
     UITableViewCell cell = null; 
     var item = cellItems [indexPath.Section] [indexPath.Row]; 
     switch (item.DisplayType) { 
     case DetailType.Name: 
      cell = tableView.DequeueReusableCell (cellIdentifier + "_name")as NameEditCell; 
      if (cell == null) { 
       cell = NameEditCell.Create(); 
      } 
      ((NameEditCell)cell).BindFields (item); 
      break; 
     case DetailType.Phone: 
      cell = tableView.DequeueReusableCell (cellIdentifier + "_phone")as PhoneEditCell; 
      if (cell == null) { 
       cell = PhoneEditCell.Create(); 

      } 
      ((PhoneEditCell)cell).BindFields (item); 
      break; 
     case DetailType.Email: 
      cell = tableView.DequeueReusableCell (cellIdentifier + "_email")as EmailEditCell; 
      if (cell == null) { 
       cell = EmailEditCell.Create(); 

      } 
      ((EmailEditCell)cell).BindFields (item); 
      break; 
     case DetailType.Property: 
      cell = tableView.DequeueReusableCell (cellIdentifier + "_property")as PropertyEditCell; 
      if (cell == null) 
       cell = PropertyEditCell.Create(); 
      ((PropertyEditCell)cell).BindFields (item); 
      break; 
     case DetailType.Address: 
      cell = tableView.DequeueReusableCell (cellIdentifier + "_address")as AddressEditCell; 
      if (cell == null) { 
       cell = AddressEditCell.Create(); 
      } 
      ((AddressEditCell)cell).BindFields (item); 
      break; 
     } 

     return cell; 
    } 
} 

你怎麼會在MVVMCross做到這一點結合或使用示例中描述的模板可以說明綁定到帶有模板的列表?在Android,iOS和Windwos的電話

回答

2

多態性列表視圖中https://github.com/MvvmCross/MvvmCross-Samples/tree/master/WorkingWithCollections

在iOS中被示出,本示例使用基於各個項目,其切換識別符的自定義數據源:

 protected override UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, 
                   object item) 
     { 
      NSString cellIdentifier; 
      if (item is Kitten) 
      { 
       cellIdentifier = KittenCellIdentifier; 
      } 
      else if (item is Dog) 
      { 
       cellIdentifier = DogCellIdentifier; 
      } 
      else 
      { 
       throw new ArgumentException("Unknown animal of type " + item.GetType().Name); 
      } 

      return (UITableViewCell) TableView.DequeueReusableCell(cellIdentifier, indexPath); 
     } 

https://github.com/MvvmCross/MvvmCross-Samples/blob/master/WorkingWithCollections/Collections.iOS/Views/Samples/PolymorphicListItemTypesView.cs