まずはTTSectionedDataSourceを使用してください。これは、2つのNSMutableArrayを持つことでセクションをサポートします - 1つは文字列の配列で表されるセクション用で、もう1つは各セクション用のテーブル項目を持つ配列の配列です。
手紙を取得することもかなり簡単です。 UITableViewDataSourceはサポートされています。
three20で
- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView;
と基底クラスがこれを行うことによって、それらを抽出サポートしています。
- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView {
return [TTTableViewDataSource lettersForSectionsWithSearch:YES summary:NO];
}
あなたのための最善の解決策は、新しいデータソースを作成し、TTSectionedDataSourceからそれを継承するだろう、セクションを構築するために次のようなものを実装してください: self.items = [NSMutableArray array]; self.sections = [NSMutableArray array];完全な作業溶液の場合
NSMutableDictionary* groups = [NSMutableDictionary dictionary];
for (NSString* name in _addressBook.names) {
NSString* letter = [NSString stringWithFormat:@"%C", [name characterAtIndex:0]];
NSMutableArray* section = [groups objectForKey:letter];
if (!section) {
section = [NSMutableArray array];
[groups setObject:section forKey:letter];
}
TTTableItem* item = [TTTableTextItem itemWithText:name URL:nil];
[section addObject:item];
}
NSArray* letters = [groups.allKeys sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)];
for (NSString* letter in letters) {
NSArray* items = [groups objectForKey:letter];
[_sections addObject:letter];
[_items addObject:items];
}
three20ソースの下TTCatalogサンプルを参照し、そこに、あなたはこのコードを持っているMockDataSource.mがあります。