0

私はこの辞書を持っています:

" a) 2012 UN NEWNW" =     (
    "2012/06/04 Saudi Arabia Huge Sandstorm",
    "2012/05/27 Niger Huge Sandstorm"
);
" b) 2012 DEUX " =     (
    "2011/03/30 Niger Huge Sandstorm"
);
" c) just for TROIS" =     (
    "2011/03/30 AHuge Sandstorm over niger",
    "2011/03/30 BHuge Sandstorm over niger",
    "2011/03/30 CHuge Sandstorm over niger",
    "2011/03/30 1Huge Sandstorm over niger",
    "2011/03/30 2Huge Sandstorm over niger",
    "2011/03/30 3Huge Sandstorm over niger",
    "2011/03/30 4Huge Sandstorm over niger",
    "2011/03/30 5CHuge Sandstorm over niger",
    "2011/03/30 6Huge Sandstorm over niger "
);
" d) ****** QUATRE" =     (
    "2011/03/30 7Huge Sandstorm over niger",
    "2011/03/30 8Huge Sandstorm over niger",
    "2011/03/30 9CHuge Sandstorm over niger",
    "2011/03/30 AHuge Sandstorm over niger",
    "2011/03/30 B10CHuge Sandstorm over niger",
    "2011/03/30 **CHuge Sandstorm over niger",
    ""
);

そしてこのコードで:

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];

    }
    // Configure the cell...

    //---------- CELL BACKGROUND IMAGE -----------------------------
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:cell.frame];
    UIImage *image = [UIImage imageNamed:@"LightGrey.png"];
    imageView.image = image;
    cell.backgroundView = imageView;
    [[cell textLabel] setBackgroundColor:[UIColor clearColor]];
    [[cell detailTextLabel] setBackgroundColor:[UIColor clearColor]];

    NSArray *allKeys = [states allKeys];
    NSString *curKey = [allKeys objectAtIndex:indexPath.section];
    NSArray *curArray = [states objectForKey:curKey];
    curValue = [curArray objectAtIndex:indexPath.row];
    //Arrow 
    cell.textLabel.text = curValue;

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

    [[cell textLabel] setFont:[UIFont systemFontOfSize:12.0]];
    return cell;
}

セクションの順序は c) b) a) d) です。誰が私を助けてくれますか?

4

4 に答える 4

2

NSDictionary クラス リファレンスから:

allKeys ディクショナリのキーを含む新しい配列を返します。

- (NSArray *)allKeys

戻り値 ディクショナリのキーを含む新しい配列、またはディクショナリにエントリがない場合は空の配列。

考察 配列内の要素の順序は定義されていません。

したがって、この配列をソートする必要があります。

于 2012-06-14T11:42:47.663 に答える
0

辞書には予測可能な順序がありません。allKeysセクションで選択する前にソートする必要があります。

于 2012-06-14T11:41:38.787 に答える
0

NSArrayの問題には順序がないため、実際には辞書の問題ではありません。キー名に従って配列をソートしてください。

于 2012-06-14T11:42:24.770 に答える
0

次の 2 つの選択肢があります。

1.ディクショナリの配列を作成し、このディクショナリを必要な順序で格納し、cellForRowAtIndexPath で同じ配列を使用します。

2. indexPath.row を提供する代わりに、辞書キーを手動で提供することにより、セクションとアクセス辞書キーを比較します。

于 2012-06-14T11:43:30.257 に答える