使用MvvmmCross的单触式分组表

本文关键字:单触式 MvvmmCross 使用 | 更新日期: 2023-09-27 17:52:11

如何使用MvvmCross在MonoTouch中实现具有分组表的视图,从而获得如下内容:

http://www.yetanotherchris.me/storage/downloads/UITableViewController.png

现在我有这段代码,但我无法将UITableViewStyle更改为Grouped:

public partial class HomeView : MvxBindingTouchTableViewController<HomeViewModel>
{
    public HomeView(MvxShowViewModelRequest request)
        : base(request)
    {
    }
    public override void ViewDidLoad()
    {
        base.ViewDidLoad();
        NavigationItem.SetRightBarButtonItem(new UIBarButtonItem("History", UIBarButtonItemStyle.Bordered, (sender, e) => ViewModel.DoGoToHistory()), false);
        var source = new MvxActionBasedBindableTableViewSource(
            TableView,
            UITableViewCellStyle.Value1,
            new NSString("HomeView"),
            "{'TitleText':{'Path':'Date'},'DetailText':{'Path':'Location'},'SelectedCommand':{'Path':'ViewDetailCommand'}}",
            UITableViewCellAccessory.DisclosureIndicator);
        this.AddBindings(
            new Dictionary<object, string>()
            {
            { source, "{'ItemsSource':{'Path':'List'}}" },
            { this, "{'Title':{'Path':'TestTitle'}}"}
        });
        TableView.Source = source;
        TableView.ReloadData();
    }
}

有人知道怎么做吗?

使用MvvmmCross的单触式分组表

您的图片只显示了一个部分。。。。假设你只想找一个部分,但是这个分组样式,那么你所需要做的就是引入UITableViewStyle.grouped。

我不确定当前的MvxTableViewController是否为您公开了这一点,因此您可能需要编辑Mvx源以添加适当的构造函数:

    protected MvxTouchTableViewController(MvxShowViewModelRequest request, UITableViewStyle style = UITableViewStyle.Plain)
        : base(style)
    {
        ShowRequest = request;
    }

    protected MvxBindingTouchTableViewController(MvxShowViewModelRequest request, UITableViewStyle style = UITableViewStyle.Plain)
        : base(request, style)
    {
    }

或者,您可以使用基本视图控制器(在其中添加表作为子视图(,而不是表视图派生的视图控制器。


如果你想要多个组,那么你需要做更多的工作,因为你需要弄清楚绑定的TableViewSource是如何计算出节的数量和每个节中的项目数量的。

    public class UserView : MvxTableViewController<UserViewModel>
    {
        public UserView()
            :base(UITableViewStyle.Grouped)
        {
        }
    }

记住要使构造函数公开且无参数。