-、建立 UITableView

DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 320, 420)];

[DataTable setDelegate:self];

[DataTable setDataSource:self];

[self.view addSubview:DataTable];

[DataTable release];

二、UITableView各Method说明

//Section总数

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

return TitleData;

}

// Section Titles

//每个section显示的标题

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

return @"";

}

//指定有多少个分区(Section),默认为1

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

return 4;

}

//指定每个分区中有多少行,默认为1

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

}

//绘制Cell

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

static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:

SimpleTableIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault

reuseIdentifier: SimpleTableIdentifier] autorelease];

}

cell.p_w_picpathView.p_w_picpath=p_w_picpath;//未选cell时的图片

cell.p_w_picpathView.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];

三、在UITableViewCell上建立UILable多行显示

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

static NSString *CellIdentifier = @"Cell";

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];

if (cell == nil) {

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];

UILabel *Datalabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, 320, 44)];

[Datalabel setTag:100];

Datalabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

[cell.contentView addSubview:Datalabel];

[Datalabel release];

}

UILabel *Datalabel = (UILabel *)[cell.contentView viewWithTag:100];

[Datalabel setFont:[UIFont boldSystemFontOfSize:18]];

Datalabel.text = [data.DataArray objectAtIndex:indexPath.row];

cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;

}

//选中cell时的颜色

typedef enum {

UITableViewCellSelectionStyleNone,

UITableViewCellSelectionStyleBlue,

UITableViewCellSelectionStyleGray

} UITableViewCellSelectionStyle

//cell右边按钮格式

typedef enum {

UITableViewCellAccessoryNone, // don't show any accessory view

UITableViewCellAccessoryDisclosureIndicator, // regular chevron. doesn't track

UITableViewCellAccessoryDetailDisclosureButton, // blue button w/ chevron. tracks

UITableViewCellAccessoryCheckmark // checkmark. doesn't track

} UITableViewCellAccessoryType

//是否加换行线

typedef enum {

UITableViewCellSeparatorStyleNone,

UITableViewCellSeparatorStyleSingleLine

} UITableViewCellSeparatorStyle//改变换行线颜色

tableView.separatorColor = [UIColor blueColor];

转自:http://no001.blog.51cto.com/1142339/637651

转载于:https://blog.51cto.com/ifeng7/1074300

TableView详解相关推荐

  1. iOS TableView 使用详解

     IOS TableView 详解 一.建立 UITableView DataTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ...

  2. 详解iPhone Tableview分批显示数据

    iPhone Tableview分批显示数据是本文要介绍的内容,主要讲解的是数据的显示.iPhone屏幕尺寸是有限的,如果需要显示的数据很多,可以先数据放到一个table中,先显示10条,table底 ...

  3. tableview的详解

    一直想对对tableview 进行详解,但是一直没有坚持,好吧,废话少说,直接来干的 UITableView是 显示大型内容的列表 单行,多列 垂直滚动,没有水平滚动 大量的数据集 性能强大,而且普遍 ...

  4. iOS教程:详解iOS多图下载的缓存机制

    ios教程,ios的干货一直来不及给大家分享,小编也是一直在忙啊!今天给大家献上ios:详解iOS多图下载的缓存机制 1. 需求点是什么? 这里所说的多图下载,就是要在tableview的每一个cel ...

  5. iOS 开发:『Runtime』详解(二)Method Swizzling

    本文用来介绍 iOS 开发中『Runtime』中的黑魔法Method Swizzling. 通过本文,您将了解到: Method Swizzling(动态方法交换)简介 Method Swizzlin ...

  6. 【工厂扫码打印扫码装箱错误追溯系统】完整案例详解(PythonPyQt 源码Mysql数据库)

    一. 市场需求 目前很多工厂产品装箱过程中仍存在一些问题: 商品打包发货出错,少发,错发,漏发 --- 追溯问题到底出在哪个环节? 手工制作装箱单,发货单,打印商品条码标签,外箱标签 --- 花费太多 ...

  7. xib、stoaryboard详解

    一.xib.sb简介 1.xib执行效率的确没有代码效率高,因为加载要多一步--把xib文件加载到内存中 2.SB还会省去很多页面跳转之间的胶水代码(segue),甚至不用写代码就能实现在各个页面中切 ...

  8. QT QtableView操作详解

    本文实现了使用QtableView控件来显示数据,数据源使用txt文本作为数据源,使用了QStandardItemModel作为数据模型来实现了对TableView空间的初始化,和对txt数据源的增删 ...

  9. SDWebImage使用详解

    SDWebImage使用详解 这个类库提供一个UIImageView类别以支持加载来自网络的远程图片.具有缓存管理.异步下载.同一个URL下载次数控制和优化等特征. 使用示范的代码: UITableV ...

最新文章

  1. 抠图+修图+调色+合成+特效Photoshop核心应用5项修炼pdf
  2. 面试题 合并两个有序链表
  3. Windows8下如何使用命令行--转载
  4. 51nod 1421 最大MOD值
  5. HFSS15.0安装步骤
  6. Python3 使用推导式统计字符出现次数
  7. Alpha冲刺博客集
  8. mobilenet cpu 加速_AI降成本利器!阿里云弹性加速计算实例来了,最高节省50%推理成本...
  9. 【POJ - 3259 】Wormholes(Bellman_Ford或spfa算法,判断有向图中是否存在负环)
  10. 图的深度优先搜索(DFS)
  11. ubuntu命令和配置文件 修改IP
  12. linux qt自带例子无法,在Qt Creator中,错过了一些例子
  13. 如何运行自动 Mac 清理
  14. C#获取C# DLL中的指定接口的所有实现实例 - qq_19759475的博客 - CSDN博客
  15. 电子计算机按用途分类包括,计算机的分类试题解析
  16. 股票交易接口的分类webService接口
  17. Android Studio开启DDMS查看手机文件
  18. 进不了PE,进PE黑屏或点阵屏怎么办
  19. 了解Windows WDDM 驱动程序
  20. java实现图片上传至本地

热门文章

  1. 请求solr服务器未响应,solr与tomcat整合
  2. c语言equal,C ++中的ratio_equal()示例
  3. python 银行工作_Python:银行系统实战(一)
  4. 解决 swap file “*.swp”already exists!问题
  5. 虚拟化运维工具医院解决方案
  6. APP技巧:微信中这6个设置建议关闭,可以防止个人信息或将全暴露,赶快看一看吧!...
  7. 程序语言基础:解释程序基本原理笔记
  8. 超融合和服务器关系_超融合与传统服务器区别
  9. android 引入 .so,android studio引入so库方法(示例代码)
  10. 根据图片获得配色方案_配色系列(1)—从图片中获得配色灵感