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.

4

2 回答 2

1

谢谢安德斯。在过渡期间,我发现了一种不同的方法:

            _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),
                        ....
                        ....

...我会尝试两者,看看什么最适合。但是我很难找到任何文档来描述对话框类的方法,例如 Section.AddAll() 和您提供的链接中使用的其他方法。

于 2012-06-17T18:41:53.717 回答
0

如果要在现有对话框视图中创建列表,例如,可以创建一个空Section列表并将列表中的元素添加为RadioElement:s 或CheckboxElement:s,具体取决于您希望能够添加多少元素同时选择。

为便于选择,您可能需要创建Group/RadioGroup并在您的部分中创建相应的列表元素时引用此组。

这是一个创建新Section元素并添加列表元素的快速示例,假设只能同时选择一个元素:

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));

如果您想要更专业地处理列表中的元素或与列表操作关联的事件,您可能需要子类化RadioElementCheckboxElement. 在这个 SO question的答案中有一个很好的例子来说明如何做到这一点。

于 2012-06-17T08:33:13.567 回答