編集:更新されたコードNSDictionaryの
私は、各セクション内のテーブルセクションから辞書と、インデックスリストを作成しようとしていますので、セクションの文字がキーになります...私が持っているセクションの場合:
self.collation = [UILocalizedIndexedCollation currentCollation];
NSInteger index, sectionTitlesCount = [[collation sectionTitles] count];
NSMutableArray *newSectionsArray = [[NSMutableArray alloc] initWithCapacity:sectionTitlesCount];
NSString *alphabet = [[NSString alloc] initWithString:@"ABCDEFGHIJKLMNOPQRSTUVWXYZ"];
for (index = 0; index < sectionTitlesCount; index++) {
NSMutableArray *array = [[NSMutableArray alloc] init];
[newSectionsArray addObject:array];
NSString *letter = [alphabet substringWithRange:NSMakeRange(index, 1)];
[myDict setObject:newSectionsArray forKey:letter];
[array release];
}
これはでクラッシュ:私はSEのためのデータを追加する必要があり、各文字について次に
'*** -[NSCFString substringWithRange:]: Range or index out of bounds'
を私はこの配列がセクション/文字キーのオブジェクトであると思います:
for (Data *myData in self.dataModel.datalist) {
NSInteger sectionNumber = [collation sectionForObject:myData collationStringSelector:@selector(myName)];
NSMutableArray *sectionData = [newSectionsArray objectAtIndex:sectionNumber];
[sectionData addObject:myData];
}
これは意味があると思います!ありがとう!!!
これは正直言ってもずっとシンプルなようですが、Appleの例はあいまいな照合ルートで私を送ってくれました!そのフィルタリングされた配列は、フィルタリングされた検索結果に対して機能しますか?どうもありがとう!!! – medley
アップルが 'UILocalizedIndexedCollation'を使って説明する理由は、ローカリゼーションを助けるためです。上記の手法を使用すると、デバイスの現在の言語に関係なく、常に英語のアルファベットが提供されます。 –
OK、情報ありがとうございます。アップルが見つけたインデックス付きのテーブルビューの唯一のデモだった。 – medley