MonoTouch.Dialog - RootElement的Group为null或不是RadioGroup

时间:2012-04-12 15:28:37

标签: c# xamarin.ios monotouch.dialog

我正在使用Monotouch.Dialog,并遇到此错误:

The RootElement's Group is null or is not a RadioGroup

我正在使用的代码如下,我添加了注释,告诉你变量的状态:

        var groupSortChoices = new RadioGroup("S", Extensions.GetValues<PeopleDirectoryGroupSortEnum>().IndexOfItem (i => i.Element == Extensions.GetValue<PeopleDirectoryGroupSortEnum>(Options.GroupAndSort)).Value);
// new RadioGroup("S", 0)
        var nameDisplayChoices = new RadioGroup("N", Extensions.GetValues<PeopleDirectoryNameDisplayEnum>().IndexOfItem (i => i.Element == Extensions.GetValue<PeopleDirectoryNameDisplayEnum>(Options.NameDisplay)).Value);
// new RadioGroup("N", 0)

        var gsElems = Extensions.GetValues<PeopleDirectoryGroupSortEnum>()
            .Select(e => new RadioElement(e, "S"))
            .ToArray();
// String[4] array of this enum's values
        var ndElems = Extensions.GetValues<PeopleDirectoryNameDisplayEnum>()
            .Select(e => new RadioElement(e, "N"))
            .ToArray();
// String[2] array of this enum's values

        groupSortElement = new RootElement("Grouping and Sorting", groupSortChoices)
        {
            new Section("Grouping and Sorting")
            {
                gsElems
            },
        };

        nameDisplayElement = new RootElement("Name Display", nameDisplayChoices)
        {
            new Section("Name Display")
            {
                ndElems
            }
        };

        var root = new RootElement("Directory Options")
        {
            groupSortElement,
            nameDisplayElement
        };

        this.Root = root;

我打破了这段代码以尝试调试它。该错误肯定来自groupSortElement和nameDisplayElement。我尝试初始化我的组而不使用“S”和“N”仍然得到相同的错误。我之前已经做了几次这样的事情,并且不能为我的生活弄清楚我做错了什么。有任何想法吗?两个RadioGroups不为null,如果我注释掉groupSortElement和nameDisplayElement,则会出现一个空视图,告诉我它与这些元素有关。

1 个答案:

答案 0 :(得分:4)

我明白了。我试图将RootElements直接添加到RootElement,而不是RootElement包含的部分。