Monotouch中的分组表与MvvmCross

时间:2013-01-11 10:24:05

标签: c# xamarin.ios mvvmcross

如何使用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();
    }
}

有谁知道怎么做?

2 个答案:

答案 0 :(得分:2)

你的图片只显示了一个部分......假设你只想找一个部分,但是这个分组的样式,那么你需要做的就是以某种方式介绍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)
    {
    }

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


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

答案 1 :(得分:0)

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

请记住将构造函数设为public且无参数。