우선 TTSectionedDataSource를 사용해야합니다. 그것은 2 개의 NSMutableArray를 가짐으로써 섹션을 지원합니다. 하나는 문자열의 배열로 표현되는 섹션을위한 것이고 다른 하나는 각 섹션에 대한 테이블 항목을 갖는 배열의 배열입니다.
편지를받는 것도 매우 간단합니다. UITableViewDataSource 지원 :
- (NSArray*)sectionIndexTitlesForTableView:(UITableView*)tableView;
및 three20의 기본 클래스는이 작업을 수행하여 그들을 추출 지원 :
이
- (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을 찾을 수 있습니다.