iOS tableView索引

本文深入探讨了iOS和Android开发之间的关键区别,包括它们的平台特性、开发工具、编程语言、应用市场策略和用户体验差异。通过对比分析,帮助开发者更好地选择适合的平台进行应用开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

其实tableView的索引的实现非常简单,主要是靠下面这个方法再结合多分区实现的:

//建立浮动索引

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

    return [NSArray arrayWithObjects:@"S",@"H",@"S"nil];

}


以下的代码中的data是一个字典,indexs是字典的key所组成的数组。用字典中的数组来填充多分区中的数据。


-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{

    return [indexs count];

    

}

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

    NSString *secNum = [indexs objectAtIndex:section];

    return [[data objectForKey:secNum] count];

}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{

    static NSString *cellId = @"cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];

    if (cell == nil) {

        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];

    }

    NSInteger rowNo = indexPath.row;

    NSInteger rowSe = indexPath.section;

    cell.textLabel.text = [[data objectForKey:[indexs objectAtIndex:rowSe]] objectAtIndex:rowNo];

    return cell;

    

}

//建立浮动索引

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

    return [NSArray arrayWithObjects:@"S",@"H",@"S", nil];

}

//分区页眉

-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{

    return  [indexs objectAtIndex:section];

}

//分区页脚

//-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{

//    NSString *str = [NSString stringWithFormat:@"一共有%lu个人物",(unsigned long)[[data objectForKey:[indexs objectAtIndex:section]] count]];

//    return str;

//}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值