标签: it表格索引sectionindextitlesfosectionindexcolor |
分类: iOS |
1、自定义索引
准备数据,设计一个数组,数组里面的元素为每个section的数组。
//返回Section总数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return self.indextitles.count;
}
//返回每个Section的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [[self.sectionarray objectAtIndex:section] count];
}
//返回每个Section的title
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [self.indextitles objectAtIndex:section];
}
//返回索引栏数据
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return self.indextitles;
}
//建立索引栏和section的关联
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index
{
return [self.indextitles indexOfObject:title];
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [self.collation.sectionTitles count];
}
//返回每个Section的title
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [self.collation.sectionIndexTitles objectAtIndex:section];
}
//返回索引栏的列别数据
-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return self.collation.sectionTitles;
}
//建立关联
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString*)title atIndex:(NSInteger)index {
return [self.collation sectionForSectionIndexTitleAtIndex:index];
}
//每个Section的行数
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSArray *innerArray = [self.outerArray objectAtIndex:section];
return [innerArray count];
}
if ([self.tableViewrespondsToSelector:@selector(sectionIndexColor)])
{
self.tableView.sectionIndexColor=[UIColor colorWithHue:(136.0/360.0) // Slightly bluish green
saturation:1.0
brightness:0.60
alpha:1.0];
}