-2
我有一个iOS应用程序,我正在使用嵌套字典将数据提供给表视图。字典的结构是:访问嵌套字典中的单个元素
Dictionary<string1, Dictionary<string2, string3>> dict;
(I have named the strings here for clarification purposes)
我目前无法访问此嵌套字典中的单个元素。我想将string1
作为单元格标题,string2
为单元格文本标签,string3
为单元格详细文本标签。这是我目前用表数据源的方法:
public class SupervisionDetailSource:UITableViewSource
{
Dictionary<string, Dictionary<string, string>> dict;
string Identifier = "cell";
public SupervisionDetailSource(Dictionary<string, Dictionary<string, string>> dict)
{
this.dict = dict;
}
public override string TitleForHeader(UITableView tableView, nint section)
{
return dict.Keys.ElementAt((int)section);
}
public override UITableViewCell GetCell(UITableView tableView, NSIndexPath indexPath)
{
UITableViewCell cell = tableView.DequeueReusableCell(Identifier);
if (cell == null)
cell = new UITableViewCell(UITableViewCellStyle.Subtitle, Identifier);
//this is not right
cell.TextLabel.Text = dict[supvList.Keys.ElementAt(indexPath.Section)][dict[dict.Keys.ElementAt(indexPath.Row)]]; //string2
cell.DetailTextLabel.Text = string3 ...?
return cell;
}
public override nint RowsInSection(UITableView tableview, nint section)
{
string key = dict.Keys.ElementAt((int)section);
return dict[key].Count;
}
public override nint NumberOfSections(UITableView tableView)
{
return dict.Keys.Count;
}
}
感谢您的帮助
你所说的 “不对” 是什么意思? – Alexander
@AMomchilov我的意思是我目前的方法来访问我的字典'string2'是不正确的/不可编译 – panthor314
这并不告诉我任何我不知道的东西。这是一个编译器错误?如果是这样,那么错误信息是什么?它是运行时错误吗?如果是这样,什么是堆栈跟踪?这是一个逻辑错误?如果是这样,那么实际产出和预期产出是多少? – Alexander