0

私はこのタイプの NSDictionary を持っています:

" **********" =     (
    "20110330 7Huge Sandstorm over niger",
    "20110330 8Huge Sandstorm over niger",
    "20110330 9CHuge Sandstorm over niger",
    "20110330 AHuge Sandstorm over niger",
    "20110330 B10CHuge Sandstorm over niger",
    "20110330 **CHuge Sandstorm over niger",
    ""
);
" 2012" =     (
    "20110330 Huge Sandstorm over niger",
    ""
);
" just for the test" =     (
    "20110330 AHuge Sandstorm over niger",
    "20110330 BHuge Sandstorm over niger",
    "20110330 CHuge Sandstorm over niger",
    "20110330 1Huge Sandstorm over niger",
    "20110330 2Huge Sandstorm over niger",
    "20110330 3Huge Sandstorm over niger",
    "20110330 4Huge Sandstorm over niger",
    "20110330 5CHuge Sandstorm over niger",
    "20110330 6Huge Sandstorm over niger",
    ""
);

「 *、 2012 、テストのためだけに」、さまざまなセクションのタイトルを使用してtableViewを実行したい。そして、「20110330 7Huge Sandstorm over niger」、「20110330 8Huge Sandstorm over niger」、「20110330 9CHuge Sandstorm over niger.....」の各セクション。

お願い助けて。

4

1 に答える 1

2

各キー内のサブ要素がNSArrayであるとすると、ディクショナリ内のキーの数をセクションの数、各セクションのタイトルの実際のキーとして返すことができ、各セクションの行の数については、その特定のキーの下にある配列内の要素の数

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return [myDictionary count];//returns the number of key/object pairs
}

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    NSArray *allKeys = [myDictionary allKeys];
    return [allKeys objectAtIndex:section];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSArray *allKeys = [myDictionary allKeys];
    NSString *curKey = [allKeys objectAtIndex:section];
    NSArray *curArray = [myDictionary objectForKey:curKey];

    return [curArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //normal cell acquisition code

    NSArray *allKeys = [myDictionary allKeys];
    NSString *curKey = [allKeys objectAtIndex:indexPath.section];
    NSArray *curArray = [myDictionary objectForKey:curKey];
    NSString *curValue = [curArray objectAtIndex:indexPath.row];
    //Do something with the string
}
于 2012-06-13T15:03:03.160 に答える