1

I am new to MonoTouch from a VS/C# background and am trying to rewrite an existing c# app. I have made one simple MonoTouch app which succesfully loads data into a List<> from an XML file, and was starting to add Master/Detail code when I discovered the existence of MonoTouch.Dialog which looked like it would make my job much easier. So I started a new project using the sample code at http://docs.xamarin.com/ios/tutorials/MonoTouch.Dialog , changing the basic class to match what I needed.

But I am stuck with trying to prepopulate the DialogViewController with my existing List<>. I have tried using LoadMoreElement but cannot find an example of its use and don't know if it's the best way of doing this.

poupou
  • 43,413
  • 6
  • 77
  • 174
quilkin
  • 874
  • 11
  • 31

2 Answers2

1

Thanks Anders. In the interim period I discovered a different method:

            _rootElement = new RootElement ("Riders") 
        {
            new Section()
            {
                from x in riderList.Riders select (Element) new RootElement(x.Name) 
                {
                    new Section()
                    {
                        new StringElement("Rider",x.Name),
                        new StringElement("Club",x.Club),
                        ....
                        ....

...ill try both and see what suits best. But I'm struggling to find any documentation to describe the methods for the dialog classes, e.g. Section.AddAll() and others used in the link you have provided.

quilkin
  • 874
  • 11
  • 31
  • Here is a link to the [Monotouch API](http://docs.go-mono.com/index.aspx?link=root:/MonoTouch-lib), and this is a link to the [Monotouch.Dialog subset API](http://docs.go-mono.com/?link=N%3aMonoTouch.Dialog). – Anders Gustafsson Jun 18 '12 at 05:23
  • OK, thanks. I was viewing the documentation page on a Windows machine and the list on the left doesn't show the relevant pages when the nodes are expanded (both IE and Firefox). It works OK only with Safari on the Mac! – quilkin Jun 18 '12 at 21:41
0

If you want to create a list within an existing dialog view, you can for example create an empty Section and to this section add the list the elements from the list as RadioElement:s or CheckboxElement:s, depending on how many elements you want to be able to select simultaneously.

To facilitate selection, you may need to create a Group/RadioGroup and reference this group when you create the respective list elements in your section.

Here is a quick example of creating a new Section and adding the list elements, assuming that only one element can be selected simultaneously:

var list = new List<SomeClass> { ... };

var listGroup = new RadioGroup("grp", 0);
var listSection = new Section();

listSection.AddAll(list.Select(elem => 
    new RadioElement(elem.ToString(), "grp") as Element));

If you want more specialized handling of the elements in the list or the events associated with list actions, you may want to subclass RadioElement or CheckboxElement. There is a good example on how to do this in the answer to this SO question.

Community
  • 1
  • 1
Anders Gustafsson
  • 15,837
  • 8
  • 56
  • 114
  • @user1460828 I just want to add that if you want the list to pop up when you click on an element in for example your root dialog, then you should include the `Section` in a `RootElement` that you add to one section in your root dialog. Hopefully this is illustrated more clearly in [this](http://stackoverflow.com/questions/10802499/monotouch-dialog-after-selection-in-a-radioelement-table-how-to-update-a-depen) SO question I asked a while ago. – Anders Gustafsson Jun 17 '12 at 20:16