可用的 v3 表源有:
抽象类
-
MvxBaseTableViewSource https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxBaseTableViewSource.cs
- 仅基本功能
- no
ItemsSource
- 一般不直接使用
-
MvxTableViewSource.cs https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxTableViewSource.cs
- 从基表继承并添加
ItemsSource
用于数据绑定
- 继承类只需要实现
protected abstract UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item);
具体类
-
MvxStandardTableViewSource.cs https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxStandardTableViewSource.cs
- 继承自
MvxTableViewSource
- 通过提供“标准 iPhone 手机类型”
UITableViewCellStyle
- 在这些你可以绑定
TitleText
, DetailText
, ImageUrl
和(带有一些戏弄的)配件
-
MvxSimpleTableViewSource.cs https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxSimpleTableViewSource.cs
- 继承自
MvxTableViewSource
- 为集合中的所有项目提供单一单元格类型 - via
string nibName
in the ctor
- 在这些单元格中,您可以绑定您喜欢的内容 - 观看视频(稍后)
-
MvxActionBasedTableViewSource.cs https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Views/MvxActionBasedTableViewSource.cs- 提供一些
Func<>
样式挂钩允许您实现GetOrCreateCellFor
无需继承新类MvxTableViewSource
一般我用:
- in demos:
- a
MvxStandardTableViewSource
- 因为我无需创建自定义单元即可获得列表
- in real code:
- a
MvxSimpleTableViewSource
当我只需要一种细胞类型时
- 继承自的自定义类
MvxTableViewSource
当我需要多种细胞类型时 - 例如见下文
具有多种单元格类型的通用 TableSource 通常看起来像PolymorphicListItemTypesView.cs https://github.com/slodge/MvvmCross-Tutorials/blob/master/Working%20With%20Collections/Collections.Touch/Views/Samples/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);
}
}
}
该视频有关如何创建自定义单元格的信息非常丰富,但似乎已经过时了
它是在 Xamarin 2.0 和 V3 之前的版本中制作的,但原理非常相似。
该文章的代码已更新 - 请参阅https://github.com/slodge/MvvmCross-Tutorials/tree/master/MonoTouchCellTutorial https://github.com/slodge/MvvmCross-Tutorials/tree/master/MonoTouchCellTutorial
除此之外:
-
N+1 系列中有很多表格使用的演示 - 索引为http://mvvmcross.wordpress.com http://mvvmcross.wordpress.com
- N=2 和 N=3 是非常基本的
- N=6 和 N=6.5 涵盖了一个书单(一个很好的起点)
- N=11 涵盖集合视图
- N=12 到 N=17 使用数据库中的列表/表创建一个大型应用程序
“使用集合”示例有相当多的表和列表代码 -https://github.com/slodge/MvvmCross-Tutorials/tree/master/Working%20With%20Collections https://github.com/slodge/MvvmCross-Tutorials/tree/master/Working%20With%20Collections
Evolve 演示期间使用表格 -http://xamarin.com/evolve/2013#session-dnoeeoarfj http://xamarin.com/evolve/2013#session-dnoeeoarfj
还有其他可用示例 - 请参阅https://github.com/slodge/MvvmCross-Tutorials/ https://github.com/slodge/MvvmCross-Tutorials/(或者在 GitHub 上搜索 mvvmcross - 其他人也在发布示例)
另外,我在常规 MvxViewController 中使用 UITableView,因为我似乎无法让 MvxTableViewController 与 xib 一起使用,这个问题似乎表明目前不可能。
我认为这个问题已经得到解决 - 请参阅Mcx TableViewController.vs#L33 https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxTableViewController.cs#L33