iOS之UITableView的使用——多分区表格以及分区索引
1、.h
#import <UIKit/UIKit.h>@interface FKViewController : UIViewController<UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) IBOutlet UITableView *table;@end
2、.m
#import <QuartzCore/QuartzCore.h>
#import "FKViewController.h"@interface FKViewController ()@end@implementation FKViewController
NSDictionary* tableData;
NSArray* stories;
- (void)viewDidLoad
{[super viewDidLoad];tableData = [NSDictionary dictionaryWithObjectsAndKeys:[NSArray arrayWithObjects:@"孙悟空" , @"猪八戒", @"牛魔王", @"蜘蛛精" , @"唐僧" , @"沙和尚" , nil] , @"西游记",[NSArray arrayWithObjects:@"宝玉" , @"黛玉", @"元春", @"探春" , @"惜春" , @"可卿" , nil] , @"红楼梦",[NSArray arrayWithObjects:@"武松" , @"林冲", @"鲁达", @"杨志" , @"宋江" , @"史进" , nil] , @"水浒",[NSArray arrayWithObjects:@"关羽" , @"刘备", @"张飞", @"曹操" , @"张辽" , @"吕布" , nil] , @"三国演义", nil];// 获取tableData的所有key排序后组成的数组stories = [[tableData allKeys]sortedArrayUsingSelector:@selector(compare:)];self.table.dataSource = self;self.table.delegate = self;
}
// UITableViewDataSource协议中的方法,该方法的返回值决定表格包含多少个分区
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{// stories集合包含多少个元素,就包含多少个分区return stories.count;
}
// UITableViewDataSource协议中的方法,该方法的返回值决定指定分区包含多少个元素
- (NSInteger)tableView:(UITableView *)tableViewnumberOfRowsInSection:(NSInteger)section
{// 获取指定分区对应stories集合中的元素NSString* story = [stories objectAtIndex:section];// 该stories集合元素包含多少个人物,该分区就包含多少表格行return [[tableData objectForKey:story] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableViewcellForRowAtIndexPath:(NSIndexPath *)indexPath
{// 获取分区号NSUInteger sectionNo = indexPath.section;// 获取表格行的行号NSUInteger rowNo = indexPath.row;NSString* story = [stories objectAtIndex:sectionNo];static NSString* cellId = @"cellId";UITableViewCell* cell = [tableViewdequeueReusableCellWithIdentifier:cellId];if(cell == nil){cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];}// 将单元格的边框设置为圆角cell.layer.cornerRadius = 12;cell.layer.masksToBounds = YES;// 为表格行的textLabel设置文本cell.textLabel.text = [[tableData objectForKey:story]objectAtIndex:rowNo];return cell;
}
// UITableViewDataSource协议中的方法,该方法的返回值用于在表格右边建立一列浮动的索引。
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{return stories;
}
// UITableViewDataSource协议中的方法,该方法的返回值决定指定分区的页眉
- (NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{return [stories objectAtIndex:section];
}
// UITableViewDataSource协议中的方法,该方法的返回值决定指定分区的页脚
- (NSString*) tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
{NSString* story = [stories objectAtIndex:section]; return [NSString stringWithFormat:@"一共有%d个人物", [[tableData objectForKey:story] count]];
}
@end
iOS之UITableView的使用——多分区表格以及分区索引相关推荐
- iOS 8 UITableView分隔符插入0不起作用
本文翻译自:iOS 8 UITableView separator inset 0 not working I have an app where the UITableView 's separat ...
- hive动态分区shell_Hive动态分区 参数配置及语法
Hive本身是不支持动态分区的.. 但动态分区是真的方便啊..不然手动维护要累死..按日期甚至小时来分区时动辄就好几千上万的分区..手动到哪一年去..? 想要用动态分区要先做一些设置来修改默认的配置. ...
- hive中的单分区与多分区在hadoop上的对应关系
分区叫法 表格举例 不同种类分区在HDFS上存放的文件结构 单分区/一级分区/主分区 t1 /user/hive/warehouse/t1/department=depart-1 多分区/多级分区/副 ...
- hive的静态分区与动态分区-用法实例
概述 本文是对[3]的复现 所有的SQL操作都在下方gitee链接中 https://gitee.com/appleyuchi/Flink_Code/blob/master/hive动态静态分区/hi ...
- hive 修改分区备注_Hive分区、分桶操作及其区别
点击上方"风控圈子" 选择"星标"公众号 每天早上8:30,一起实现自我增值 Hive是基于Hadoop的一个数据仓库工具,使用类SQL的查询语句,即HQL对 ...
- 主分区、扩展分区、逻辑分区
一.主分区.扩展分区和逻辑分区 1.概念 主分区:也叫引导分区,最多能创建4个,最少有1个,当主分区创建了4个后,主分区和扩展分区就没有存在于这个世界上的理由了. 扩展分区:最多一个.严格意义上来讲它 ...
- Linux 硬盘分区、分区命名和分区格式化
开始 Linux下只有根分区.交换分区和其他分区(比如数据分区.日志分区等,具体名字都可以自定义).一切皆文件. 目录 开始 内容 硬盘 硬盘分区 分区命名 分区格式化 课后作业(答案见评论) 内容 ...
- linux挂载分区失败,Ubuntu分区挂载错误与Grub引导错误的修复
可以启动,但启动到一半的时候提示检查分区出错"fsck died with exit status 8",这时还可以通过Ctrl+Alt+Delete进入桌面,是因为Ubuntu ...
- linuxquot;/quot;分区名称,linux分区,磁盘系统的管理,文件系统制作
最近又开始重新拾起linux了,因为工作中用的很少,所以看得东西很容易就忘记了. 这几天看了下linux的分区,以及如何制作文件系统等相关命令的用法,下面就按照这个流程来讲一讲,免得自己日后忘记了. ...
- mysql 表分区 django_MySQL partition分区I
Mysql5.1已经发行很久了,本文根据官方文档的翻译和自己的一些测试,对Mysql分区表的局限性做了一些总结,因为个人能力以及测试环境的原因,有可能有错误的地方,还请大家看到能及时指出,当然有兴趣的 ...
最新文章
- 类执行方法的过程与运行时
- 让图片动起来,特朗普和蒙娜丽莎深情合唱《Unravel》
- window7环境下ZooKeeper的安装运行及监控查看
- 学习笔记(10):Python网络编程并发编程-粘包现象
- android 系统gpu 调试_【资讯】高通公布首批可OTA更新GPU驱动手机:谷歌Pixel 4/三星S10在列...
- java excel 超链接_Java 编辑、删除Excel中的超链接
- adc采集出来一段波形 如何求周期与频率_DMA+ADC快速采集直流无刷电机电流
- element ui 1.4 升级到 2.0.11
- 如何查看wifi信息并对其进行管理?这些app帮你一键掌控你的wifi信息
- oracle11g本地安装,windows64位机oracle11g+pl/sql安装教程图解
- Kotlin自定义android 控件
- STM32 CAN通信的学习笔记总结(从小白开始)
- 瑞盟485/422接口电路MS2576完全替代AM26C31
- SpringBoot+MangoDB查询操作(MongoTemplate)总结
- jstack命令详解
- oracle 查看指标 tps(Transactions Per Second)
- dll注册加载失败解决方法,请确保二进制的解决办法(无数踩坑试出来的)
- 政考网:公务员备考需要多久?
- 【el-dialog + video】控制视频弹框的显示与隐藏
- 与墨云同行 |低头有坚定的脚步,抬头是清晰的远方