我正在使用 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”的情况下初始化我的组,但仍然出现相同的错误。我以前做过几次,但我一生都无法弄清楚我做错了什么。有任何想法吗?这两个 RadioGroup 不为空,如果我注释掉 groupSortElement 和 nameDisplayElement,就会出现一个空视图,告诉我这与这些元素有关。