2016-06-29 4 views
-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; 
    } 
} 

어떤 도움

+0

당신이 "옳지 않다"무엇을 의미합니까? – Alexander

+0

@AMomchilov 제 사전의'string2'에 대한 현재 접근법이 옳지 않거나 컴파일 할 수 없음을 의미합니다. – panthor314

+0

아무 것도 말해주지 않은 것 같습니다. 컴파일러 오류입니까? 그렇다면 오류 메시지는 무엇입니까? 런타임 오류입니까? 그렇다면 스택 트레이스는 무엇입니까? 논리적 오류입니까? 그렇다면 실제 출력과 예상 출력은 무엇입니까? – Alexander

답변

0

내가 어려움이 중첩 된 요소에 액세스하는 데했지만 나는 그것이 작동하도록지고 결국 주셔서 감사합니다 다음은 테이블 데이터 소스 내 현재의 접근 방식이다. 나는이 문제에 어떻게 접근해야하는지에 대한 오해가 있었다. (당신이 더 중첩 될수록 조금 털이 나는 것은 말할 것도 없다.)

내 솔루션 :

cell.TextLabel.Text = dict[dict.Keys.ElementAt(indexPath.Section)].Keys.ElementAt(indexPath.Row); //string2 
cell.DetailTextLabel.Text = dict[dict.Keys.ElementAt(indexPath.Section)][dict[dict.Keys.ElementAt(indexPath.Section)].Keys.ElementAt(indexPath.Row)]; //string3 
+2

정말 조금만 청소 해보십시오. 꽤 털이 많습니다. – Alexander