0

I have an NSMutableArray filled by external source. This array is an array of NSDictionaries - which actually contain xml key value pairs within them. Somewhat like:

<element1>
  <key1=valueA>
  <key2=valueB>
</element1>
<element2>
  <key1=valueB>
  <key2=valueB>
</element2>
<element3>
  <key1=valueB>
  <key2=valueC>
</element3>

And so on.

Now, all my key1=valueB records must go into Section 1 of UITableView. In above xml, it will be element2 and element3. And rest should go to section 2.

I know some solutions that advise to create two arrays from beginning, but that filtering is somewhat complex based on above structure. I am seeking something concise, and if possible, in-built UITableView functionality.

4

1 回答 1

0

我认为最简单的方法是先分成两个数组。幸运的是,我发现这很容易:

   for (NSMutableDictionary *theDict in sourceMutableArray)
   {
     if ([theDict objectForKey:@"key1"] != nil)
     {
       if ([[theDict objectForKey:@"key1"] isEqualToString:@"valueB"])
       {
          [destinationMutableArray1 addObject:theDict];
       }
       else
       {
          [destinationMutableArray2 addObject:theDict];
       }            
     }
   }
于 2012-10-27T11:34:17.230 回答