(原本取至D了个L微信公众号)

UITableView 详解

一、建立 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.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];

三、在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];

 
 

微信扫一扫
关注该公众号

UITableView 详解 ()的更多相关文章

  1. UITableView详解(1)

    一,UITableView控件使用必备,红色部分是易错点和难点 首先创建一个项目,要使用UITableView就需要实现协议<UITableViewDataSource>,数据源协议主要完 ...

  2. UITableView详解(2)

    承接上文,再续本文 一,首先我们对上次的代码进行改进,需要知道的一点是,滚动视图的时候,我们要创建几个视图,如果一个视图显示一个图片占据整个屏幕,对于滚动视图我们只需要创建三个视图就可以显示几千给图片 ...

  3. 【转】UITableView详解(UITableViewCell

    原文网址:http://www.kancloud.cn/digest/ios-1/107420 上一节中,我们定义的cell比较单一,只是单调的输入文本和插入图片,但是在实际开发中,有的cell上面有 ...

  4. UITableView详解(转)

    首先.对UITableView进行讲解,下面有对它进行实际的应用 UITableView 显示大型内容的列表 单行,多列 垂直滚动,没有水平滚动 大量的数据集 性能强大,而且普遍存在于iPhone的应 ...

  5. UITableView 详解 教程

    看TableView的资料其实已经蛮久了,一直想写点儿东西,却总是因为各种原因拖延,今天晚上有时间静下心来记录一些最近学习的TableView的知识.下面进入正题,UITableView堪称UIKit ...

  6. UITableView详解

    一.建立 UITableView DataTable = [[UITableView alloc] initWithFrame:CGRectMake(, , , )]; [DataTable setD ...

  7. 《iOS 7 应用开发实战详解》

    <iOS 7 应用开发实战详解> 基本信息 作者: 朱元波    管蕾 出版社:人民邮电出版社 ISBN:9787115343697 上架时间:2014-4-25 出版日期:2014 年5 ...

  8. iPhone应用开发 UITableView学习点滴详解

    iPhone应用开发 UITableView学习点滴详解是本文要介绍的内容,内容不多,主要是以代码实现UITableView的学习点滴,我们来看内容. -.建立 UITableView DataTab ...

  9. IOS中表视图(UITableView)使用详解

    IOS中UITableView使用总结 一.初始化方法 - (instancetype)initWithFrame:(CGRect)frame style:(UITableViewStyle)styl ...

随机推荐

  1. linux 常用alias

    alias qqcom='cd /usr/local/qqcom_app/' alias php_c='cd /usr/local/php/lib/' alias ap_c='cd /usr/loca ...

  2. mvc无法找到资源

    昨天装了vs2015,但是第二步没有完成.今天急急忙忙的用13打开一个mvc的项目,但是添加的控制器怎么都不能访问. 无法找到资源. 说明: HTTP 404.您正在查找的资源(或者它的一个依赖项)可 ...

  3. 如何搭建Struts2环境

    1.解压下载到的struts-2.3.16压缩包. 2.将struts2-blank\WEB-INF\lib 下的jar包复制到Eclipse项目下的libs文件夹下. 3.struts-2.3.16 ...

  4. Python开发专业工具推荐

    PyCharm,jetbrains公司出品,必是精品!! 版本:2016.3.1 下载:https://www.jetbrains.com/pycharm/download/#section=wind ...

  5. iPhone开发之UIScrollView初步

    来源:http://blog.csdn.net/htttw/article/details/7891396 iPhone开发之UIScrollView初步 今天我们初步介绍以一下iPhone开发中的U ...

  6. git的忽略文件和删除文件操作

    1 删除工作区和暂存去的a文件$ git rm a 2只删除暂存去的 a文件,a文件就不被跟踪了.可以执行git add a从新添加回暂存去$ git rm --cached a 3 git mv 操 ...

  7. Ubuntu 13.10 安装 ia32-lib

    Ubuntu 13.10下面不参直接安装ia32-libs,直接安装的时候会提示下面的信息: output$ sudo apt-get install ia32-libs Reading packag ...

  8. 20145305 《Java程序设计》第9周学习总结

    教材学习内容总结 1.厂商在操作JDBC驱动程序时,依方式可将驱动程序分为4种类型: JDBC-ODBC Bridge Driver Native API Driver JDBC-Net Driver ...

  9. [ActionScript 3.0] flash如何访问父级或者舞台上的变量、函数等的方法

    方法一: 进行类型转换,先将root.parent强制转换为MovieClip类型,再进行使用,如下:MovieClip(root).i.MovieClip(this.parent).i.MovieC ...

  10. [ActionScript 3.0] AS3 绘制星形

    package { import flash.display.Sprite; import flash.events.Event; /** * @author Frost.Yen * @E-mail ...