標簽: 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];
}