2014-07-01 3 views
0

나는 아래로 내 PLIST에서 다른 사전에서 사전을 가지고 : 사용자는 현재 문자열을 검색하기 위해 검색 창을 사용nsdictionary와 함께 술어를 사용하는 방법?

<dict1>Root 
     <dict2>A 
      <dict3>Apple 
        <string>"About Apple..." 
      <dict3>Arrow 
        <string>"About Arrow..." 
     <dict2>B 
      <dict3>Ball 
        <string>"About Ball..." 
     <dict2>C 

        etc... 

. 세 번째 레벨을보고 술어를 사용하여 각 문자열을 비교하고 결과를 반환하고이를 테이블 뷰 셀에 전달하는 방법은 무엇입니까?

이 비디오 자습서를 따라 시도했지만 술어에 실패합니다. 그는 내가 무엇을 볼 수에서 배열에 자신의 사전을 작성했습니다

https://www.youtube.com/watch?v=UE4h_Td6W6U

. 내 것은 좀 더 복잡해 보입니다.

본인은 새로운 기능이므로 도움을 주실 수 있습니다.

답변

2

찾고있는 사전을 찾을 때까지 사전 목록을 탐색해야합니다.

NSString *plistPath = [[NSBundle mainBundle] pathForResource:@"YOURPLIST" ofType:@"plist"]; 
    NSMutableDictionary *dictionary = [NSDictionary dictionaryWithContentsOfFile:plistPath]; //This puts you into the root directory 
    NSMutableDictionary *secondLevel = [NSMutableDictionary dictionaryWithDictionary:[dictionary objectForKey:[NSString stringWithFormat:@"A"]]]; //or B or C etc 
    NSMutableDictionary *thirdLevel = [NSMutableDictionary dictionaryWithDictionary:[dictionary objectForKey:[NSString stringWithFormat:@"Apple"]]]; 

이렇게하면 문자열을 가져올 수 있도록 Apple 사전에 넣을 수 있습니다.이 문자열은 첨부 된 키가 필요합니다. 당신이 엄격하게 문자열을 검색하는 경우,이 Search String in NSDictionary store in NSMutableArray

같은 뭔가를 할 수

NSString *string = [thirdLevel objectForKey:@"Some key name"]; 

: 귀하의 사전

<key>Some key name</key> 
    <string>About Apple...</string> 

과 같아야합니다 그리고 당신은을 통해 키를 사용하여 문자열을 가져올 수

관련 문제