UITableView详解
来源:互联网 发布:福州seo技巧培训 编辑:程序博客网 时间:2024/06/07 04:03
一、iOS中创建UITableView控件
1、通过代码创建
- UITableView *tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,320,460)];
- [tableView setDelegate:self];
- [tableView setDataSource:self];
- [slef.view addSubView:tableView];
二、UITableView中的各种Method
//获取Section title的数组
- -(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
- return titleData;
- }
//指定每个section的标题(title)
- -(NSString *)tableView:(UITableView *)tableView titleForHanderInSection:(NSInteger)section{
- return @"sectionTitle";
- }
//指定有多少个分区(Section),默认值为1
- -(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
- return number;
- }
//指定每个分区(Section)有多少行,默认值为1
- -(NSInteger)tableView:(NSTableView *)tableView numbleOfRowsInSection:(NSInteger)section{
- return rowsCount;
- }
//绘制Cell(学android的同学应该知道,这个类似于android adapter的中getView,用于绘制每个item)
- -(NSTableViewCell *)tableView:(NSTableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
- static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
- UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:SimpleTableIdentifier];
- if(cell==nil){
- cell = [[UITableView alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableViewIdentifier];
- }
- cell.imageView.image=image;//未选cell时的图片
- cell.imageView.highlightedImage=highlightImage;//选中cell后的图片
- cell.text=//.....
- return cell;
- }
//行缩进
- -(NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath{
- NSUInteger row = [indexPath row];
- return row;
- }
//改变行的高度
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
- return 40;
- }
//定位
- [TopicsTable setContentOffset:CGPointMake(0, promiseNum * 44 + Chapter * 20)];
//返回当前所选cell
- NSIndexPath *ip = [NSIndexPath indexPathForRow:row inSection:section];
- [TopicsTable selectRowAtIndexPath:ip animated:YES scrollPosition:UITableViewScrollPositionNone];
- [tableView setSeparatorStyle:UITableViewCellSelectionStyleNone];
//选中Cell响应事件
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
- [tableView deselectRowAtIndexPath:indexPath animated:YES];//选中后的反显颜色即刻消失
- }
//判断选中的行(阻止选中第一行)
- -(NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- NSUInteger row = [indexPath row];
- if (row == 0)
- return nil;
- return indexPath;
- }
//划动cell是否出现del按钮
- - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
- }
- //编辑状态
- - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
- forRowAtIndexPath:(NSIndexPath *)indexPath
- {
- }
- [topicsTable setContentSize:CGSizeMake(0,controller.promiseNum * 44)];
- //右侧添加一个索引表
- - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView{
- }
- //返回Section标题内容
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
- }
- //自定义划动时del按钮内容
- - (NSString *)tableView:(UITableView *)tableView
- titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
- //跳到指的row or section
- [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:NO];
1 0
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UItableView 详解
- UITableview 详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- UITableView详解
- IOS 获取指定月的第一天和最后一天
- C++中的指针和引用
- JVM 学习笔记-java程序编译和运行的过程
- JAVA EE架构师 需要具备的知识
- IM相关梳理
- UITableView详解
- Flume Avro Source 远程连接拒绝解决方法
- JS中 event属性方法总结
- 050.Hex2String 十六进制转字符串
- 文件加载和保存
- 图片上传4-bug修复
- 049.Array Arg 数组作为函数的参数
- Inotify测试(1):PyInotify、Thread测试
- Javascript 中数字的部分知识总结: