TableView表格索引的建立

1、自定义索引

准备数据,设计一个数组,数组里面的元素为每个section的数组。

//返回Section总数

-(NSInteger)numberOfSectionsInTableView:(UITableView*)tableView

{

   return self.indextitles.count;

}

//返回每个Section的行数

-(NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(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 *)tableViewsectionForSectionIndexTitle:(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.sectionIndexTitlesobjectAtIndex:section];

}

//返回索引栏的列别数据

-(NSArray*)sectionIndexTitlesForTableView:(UITableView *)tableView {

   return self.collation.sectionTitles;

}

//建立关联

-(NSInteger)tableView:(UITableView *)tableViewsectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {

   return [self.collationsectionForSectionIndexTitleAtIndex:index];

}

//每个Section的行数

-(NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section {

    NSArray *innerArray = [self.outerArray objectAtIndex:section];

    return [innerArray count];

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值