Mat*_*and 5 ios mvvmcross xamarin
我正在使用Xamarin和mvvmcross以及如何使用最终绑定到可观察集合的表的视图.
此视频提供了有关如何创建自定义单元格的信息,但似乎已过时.在大约42分钟时,Stuart为他的表创建了一个数据源MvxSimpleBindableTableSource,但该类似乎不存在,或者至少,我找不到它.那么用mvvmcross绑定到UITableView的"最佳"方式是什么?
此外,我在常规的MvxViewController中使用UITableView,因为我似乎无法让MvxTableViewController与xib一起工作,这个问题似乎表明目前不可能.
Stu*_*art 15
可用的v3表源是:
抽象类
ItemsSource- 一般不直接使用ItemsSource进行数据绑定protected abstract UITableViewCell GetOrCreateCellFor(UITableView tableView, NSIndexPath indexPath, object item);具体课程
MvxTableViewSourceUITableViewCellStyle TitleText,DetailText,ImageUrl(用一些挑逗)附件MvxTableViewSourcestring nibName在ctorFunc<>样式挂钩,允许您在GetOrCreateCellFor不继承新类的情况下实现MvxTableViewSource一般我用:
MvxStandardTableViewSource- 因为我得到一个列表而不必创建自定义单元格MvxSimpleTableViewSource,当我只需要一种细胞类型MvxTableViewSource我需要多个单元格类型时继承的自定义类- 例如,见下文具有多个单元格类型的常规TableSource通常看起来像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);
}
}
}
Run Code Online (Sandbox Code Playgroud)
此视频提供了有关如何创建自定义单元格的信息,但似乎已过时
它只是在Xamarin 2.0和V3之前制作,但原理非常相似.
该文章的代码已更新 - 请参阅https://github.com/slodge/MvvmCross-Tutorials/tree/master/MonoTouchCellTutorial
除此之外:
在N + 1系列中有很多表使用的演示 - 索引在http://mvvmcross.wordpress.com
"使用集合"示例有很多表和列表代码 - https://github.com/slodge/MvvmCross-Tutorials/tree/master/Working%20With%20Collections
表格在Evolve演示文稿中使用 - http://xamarin.com/evolve/2013#session-dnoeeoarfj
还有其他可用的样本 - 请参阅https://github.com/slodge/MvvmCross-Tutorials/(或在GitHub上搜索mvvmcross - 其他人也发布样本)
此外,我在常规的MvxViewController中使用UITableView,因为我似乎无法让MvxTableViewController与xib一起工作,这个问题似乎表明目前不可能.
我认为这已经修复 - 请参阅MvxTableViewController.cs#L33
| 归档时间: |
|
| 查看次数: |
3355 次 |
| 最近记录: |