从绑定表源继承的类 [英] What class to inherit from for bound table source

查看:119
本文介绍了从绑定表源继承的类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Xamarin和mvvmcross以及最终绑定到可观察集合的表的视图。

I'm using Xamarin and mvvmcross and what to have a view with a table ultimately bound to an observable collection.

视频是关于如何创建自定义单元格的信息非常丰富,但似乎已过时。大约42分钟,Stuart为他的表创建了一个源自 MvxSimpleBindableTableSource 的数据源,但该类似乎不存在,或者至少,我找不到它。那么用mvvmcross绑定到UITableView的最佳方式是什么?

This video is very informative on how to create custom cells, but appears to be out-of-date. At around 42 minutes, Stuart creates a data source for his table that derives from MvxSimpleBindableTableSource, but that class doesn't seem to exist, or at least, I can't find it. So what is the "best" way to bind to a UITableView with mvvmcross?

另外,我在常规MvxViewController中使用UITableView,因为我似乎无法让MvxTableViewController与xib一起使用,这个问题似乎表明目前无法实现。

Also, I'm using a UITableView in a regular MvxViewController because I can't seem to get the MvxTableViewController to work with a xib, which this question seems to suggest isn't currently possible.

推荐答案

可用的v3表源是:

抽象类


  • MVxBaseTableViewSource

    • 仅限基本功能

    • ItemsSource - 一般不直接使用

    • MvxBaseTableViewSource
      • base functionality only
      • no ItemsSource - generally not used directly

      • 继承自基础和addes ItemsSource 用于数据绑定

      • 继承类只需实现 protected abstract UITableViewCell GetOrCreateCellFor(UITableView tableView) ,NSIndexPath indexPath,object item);

      • inherits from the basetable and addes ItemsSource for data-binding
      • inheriting classes need only to implement protected abstract UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item);

      具体类


      • MvxStandardTableViewSource.cs

        • 继承自 MvxTableViewSource

        • 通过 UITableViewCellStyle

        • 提供'标准iPhone手机类型',你可以绑定 TitleText DetailText ImageUrl 和(带一些戏弄)附件

        • MvxStandardTableViewSource.cs
          • inherits from MvxTableViewSource
          • provides the 'standard iPhone cell types' via UITableViewCellStyle
          • within these you can bind TitleText, DetailText, ImageUrl and (with some teasing) Accessory

          • 继承自 MvxTableViewSource

          • 为集合中的所有项目提供单一单元格类型 - via 字符串nibName ctor

          • 这些单元格中你可以绑定你喜欢的内容 - 观看视频(稍后)

          • inherits from MvxTableViewSource
          • provides a single cell type for all items in the collection - via string nibName in the ctor
          • within these cells you can bind what you like - see videos (later)

          通常我在演示中使用:




            • 一个 MvxStandardTableViewSource - 因为我得到一个列表而不必创建自定义单元格

            • in demos:
              • a MvxStandardTableViewSource - because I get a list without having to create a custom cell

              • 一个 MvxSimpleTableViewSource 当我只需要Ø新单元格类型

              • 当我需要多个单元格类型时,继承自 MvxTableViewSource 的自定义类 - 例如见下文

              • a MvxSimpleTableViewSource when I only need one cell type
              • a custom class inheriting from MvxTableViewSource when I need multiple cell types - e.g. see below

              一般具有多个单元格类型的TableSource通常看起来像 PolymorphicListItemTypesView.cs

              A general TableSource with multiple cell types typically looks like PolymorphicListItemTypesView.cs:

              public class PolymorphicListItemTypesView
                  : MvxTableViewController
              {
                  public PolymorphicListItemTypesView()
                  {
                      Title = "Poly List";
                  }
              
                  public override void ViewDidLoad()
                  {
                      base.ViewDidLoad();
              
                      var source = new TableSource(TableView);
                      this.AddBindings(new Dictionary<object, string>
                          {
                              {source, "ItemsSource Animals"}
                          });
              
                      TableView.Source = source;
                      TableView.ReloadData();
                  }
              
                  public class TableSource : MvxTableViewSource
                  {
                      private static readonly NSString KittenCellIdentifier = new NSString("KittenCell");
                      private static readonly NSString DogCellIdentifier = new NSString("DogCell");
              
                      public TableSource(UITableView tableView)
                          : base(tableView)
                      {
                          tableView.RegisterNibForCellReuse(UINib.FromName("KittenCell", NSBundle.MainBundle),
                                                            KittenCellIdentifier);
                          tableView.RegisterNibForCellReuse(UINib.FromName("DogCell", NSBundle.MainBundle), DogCellIdentifier);
                      }
              
                      public override float GetHeightForRow(UITableView tableView, NSIndexPath indexPath)
                      {
                          return KittenCell.GetCellHeight();
                      }
              
                      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);
                      }
                  }
              }
              








              此视频提供了有关如何创建自定义单元格的信息,但似乎已过时

              This video is very informative on how to create custom cells, but appears to be out-of-date

              它只是在Xamarin 2.0之前和V3之前制作但原则非常相似。

              It was made just pre-Xamarin 2.0 and pre-V3 but the principles are very similar.

              该文章的代码已更新 - 请参阅 https://github.com/slodge/MvvmCross-Tutorials/tree/master/MonoTouchCellTutorial

              The code for that article has been updated - see https://github.com/slodge/MvvmCross-Tutorials/tree/master/MonoTouchCellTutorial

              除此之外:


              • N = 2且N = 3非常基本

              • N = 6且N = 6.5涵盖图书清单(一个好的起点)

              • N = 11涵盖集合视图

              • N = 12到N = 17制作一个带有列表/表格的大型应用程序数据库

              • N=2 and N=3 are very basic
              • N=6 and N=6.5 covers a book list (a good place to start)
              • N=11 covers collection views
              • N=12 to N=17 make a large app with a list/table from a database

              使用集合示例包含大量的表和列表代码 - https://github.com/slodge/MvvmCross-Tutorials/tree/master/Working%20With%20Collections

              the "Working with Collections" sample has quite a lot of Table and List code - https://github.com/slodge/MvvmCross-Tutorials/tree/master/Working%20With%20Collections

              在Evolve演示文稿中使用表格 - http ://xamarin.com/evolve/2013#session-dnoeeoarfj

              tables are used during the Evolve presentation - http://xamarin.com/evolve/2013#session-dnoeeoarfj

              还有其他可用样本 - 请参阅https://github.com/slodge/MvvmCross-Tutorials/ (或在GitHub上搜索mvvmcross - 其他人也发布样本)

              there are other samples available - see https://github.com/slodge/MvvmCross-Tutorials/ (or search on GitHub for mvvmcross - others are also posting samples)


              此外,我在常规MvxViewController中使用UITableView,因为我似乎无法获得MvxTableViewController使用xib,这个问题似乎表明目前无法实现。

              Also, I'm using a UITableView in a regular MvxViewController because I can't seem to get the MvxTableViewController to work with a xib, which this question seems to suggest isn't currently possible.

              我认为此后已修复 - 请参阅 MvxTableViewController.cs#L33

              I think that has since been fixed - see MvxTableViewController.cs#L33

              这篇关于从绑定表源继承的类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆