0

I'm trying to create an MVVMCross-based UITableView with multiple sections. The recommended way of binding data in the ViewModel to items in the table is to create a binding with an MvxTableViewSource's ItemsSource property like so:

var source = new MyCustomMvxTableViewSource(MyTableView);

this.AddBindings(new Dictionary<object, string>
{
    {source, "ItemsSource MyObservableCollection"}
});

MyTableView.Source = source;

This works fine if I don't need to have multiple sections, but I do. There's a super-complicated example of achieving this here, but I'm very much hoping that there's a much simpler way of doing this with MVVMCross. There's nothing in their documentation that helps with this, even though a table with sections is a common iOS feature.

I'm hoping someone, somewhere can point me in the direction of some code examples to help me achieve this?

Alex Smith
  • 85
  • 1
  • 9

1 Answers1

0

I think you can find a lot of answers after searching online.

We just need to implement NumberOfSections and GetViewForHeader delegate method in MyCustomMvxTableViewSource.

And don't forget to change your model struct if you want to show different sections.

Refer to Modern approach for UITableView grouping with Mvvmcross

ColeX
  • 14,062
  • 5
  • 43
  • 240
  • Thanks for your answer, but a little more is needed for successful data binding with MvvmCross, making it less straightforward than overriding the standard methods in the Source class. Hence why googling didn’t give the right answers. The link you shared helped though, so thanks for that – Alex Smith Jan 28 '18 at 10:41