- (void)viewDidLoad {
[super viewDidLoad];
[self.tabBarController.tabBar setHidden:YES];
//设置索引栏字体和背景颜色
if ([self.tableView respondsToSelector:@selector(setSectionIndexColor:)]) {
self.tableView.sectionIndexColor = [UIColor grayColor];
self.tableView.sectionIndexTrackingBackgroundColor = [UIColor blueColor];
}
sectionTitles = @[@"A",@"B",@"",@"C",@"D",@"E",@"F",@"G",@"H",@"I",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"U",@"V",@"W",@"X",@"Y",@"Z"];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return sectionTitles.count;
}
//返回每个Section的title
-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
return [sectionTitles objectAtIndex:section];
}
//返回索引栏数据
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
return sectionTitles;
}
//建立索引栏和section的关联
-(NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{
return [sectionTitles indexOfObject:title];
}
给UITableView 添加索引
最新推荐文章于 2019-07-24 18:27:06 发布