テーブルビューにアルファベット順に入力したデータを解析しました。アルファベット順は、人の名前に基づいています。次に、インデックスバーとセクションを追加する必要があります。私が作成しているのは一種の名簿です。これは、解析されたデータをセルに配置するために使用しているコードですlabel.text = [arrayOfTitle objectAtIndex:indexPath.row];
これは、テーブルビューにインデックスバーとセクションタイトルを配置するためのコードです。
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self arrayOfNames] count];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 26;
}
-(NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return [[UILocalizedIndexedCollation currentCollation] sectionIndexTitles];
}
- (NSString *)tableView:(UITableView *)aTableView titleForHeaderInSection:(NSInteger)section {
if ([self.arrayOfNames objectAtIndex:section] ) {
return [[[UILocalizedIndexedCollation currentCollation] sectionTitles]
objectAtIndex:section];
}
return nil;
}
@end
plistファイルからセクションを作成する方法は知っていますが、ここでは解析されたデータの配列しかないため、セクションに分割するのに苦労しています。ご協力ありがとうございました。