UITableView 索引的添加 sectionIndexTitlesForTableView sectionIndexColor


标签: 

it

 

表格索引

 

sectionindextitlesfo

 

sectionindexcolor

分类: 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];

}

2、使用UILocalizedIndexedCollation建立
创建一个UILocalizedIndexedCollation  这个其实固定为27个字符 A-Z 加 #  换句话说,就是索引栏固定为A-Z 加 #,创建的表格一定有27个Section,如果没有数据的话会有titleForHeaderInSection
//返回Section总数

-(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];

 

    }


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM