//右边索引 字节数(如果不实现 就不显示右侧索引)
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return sectionName;
}
//section (标签)标题显示
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [sectionName objectAtIndex:section];
}
//标签数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return sectionName.count;
}
// 设置section的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 40;
}
//点击右侧索引表项时调用
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
NSString *key = [sectionName objectAtIndex:index];
NSLog(@"sectionForSectionIndexTitle key=%@",key);
if (key == UITableViewIndexSearch) {
[tableViewProj setContentOffset:CGPointZero animated:NO];
return NSNotFound;
}
return index;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,320, 400)];
view.backgroundColor = [UIColor whiteColor];
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(8, 13, 70, 20)];
title.text = [sectionName objectAtIndex:section];
title.textColor=[UIColor whiteColor];
title.font = [UIFont systemFontOfSize:15];
title.textAlignment= NSTextAlignmentCenter;
title.backgroundColor = Rgb2UIColor(233,82,62);
[view addSubview:title];
return view;
}
// 设置cell的高度
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
CGSize size = CGSizeMake(215,2000);
CGSize labelsize = [[detailArr objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
CGFloat height = labelsize.height+10;
if (height>30) {
return height;
}
}
return 30;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(section == 0)
{
return detailArr.count;
}else
{
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailViewCell" forIndexPath:indexPath];
if (indexPath.section==0) {
cell.title.text = [nameArr objectAtIndex:indexPath.row];
cell.detaillab.text = [detailArr objectAtIndex:indexPath.row];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView {
return sectionName;
}
//section (标签)标题显示
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section {
return [sectionName objectAtIndex:section];
}
//标签数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return sectionName.count;
}
// 设置section的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
return 40;
}
//点击右侧索引表项时调用
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index {
NSString *key = [sectionName objectAtIndex:index];
NSLog(@"sectionForSectionIndexTitle key=%@",key);
if (key == UITableViewIndexSearch) {
[tableViewProj setContentOffset:CGPointZero animated:NO];
return NSNotFound;
}
return index;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0,320, 400)];
view.backgroundColor = [UIColor whiteColor];
UILabel *title = [[UILabel alloc]initWithFrame:CGRectMake(8, 13, 70, 20)];
title.text = [sectionName objectAtIndex:section];
title.textColor=[UIColor whiteColor];
title.font = [UIFont systemFontOfSize:15];
title.textAlignment= NSTextAlignmentCenter;
title.backgroundColor = Rgb2UIColor(233,82,62);
[view addSubview:title];
return view;
}
// 设置cell的高度
- (CGFloat)tableView:(UITableView *)atableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
CGSize size = CGSizeMake(215,2000);
CGSize labelsize = [[detailArr objectAtIndex:indexPath.row] sizeWithFont:[UIFont systemFontOfSize:12] constrainedToSize:size lineBreakMode:NSLineBreakByCharWrapping];
CGFloat height = labelsize.height+10;
if (height>30) {
return height;
}
}
return 30;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(section == 0)
{
return detailArr.count;
}else
{
return 1;
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
DetailViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DetailViewCell" forIndexPath:indexPath];
if (indexPath.section==0) {
cell.title.text = [nameArr objectAtIndex:indexPath.row];
cell.detaillab.text = [detailArr objectAtIndex:indexPath.row];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}