一、创建一个列表,不管代码还是nib拖拉,在nib创建的时候,记得加他的二个代理 (UITableViewDelegate UITableViewDataSource)

代码创建的话,需要关联他的代理,nib创建则不需要关联,他自动会关联。。。代码创建关联的方法为

 LXDataTable = [[UITableView alloc] initWithFrame:CGRectMake(, , , )];

 [LXDataTable setDelegate:self];

 [LXDataTable setDataSource:self];

 [self.view addSubview:DataTable];

 [LXDataTable 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 ;

 }

 //指定每个分区中有多少行,默认为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 ;

 }

 //定位

 [TopicsTable setContentOffset:CGPointMake(, promiseNum *  + Chapter * )];

 //返回当前所选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 == )

         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(,controller.promiseNum * )];

 //右侧添加一个索引表

 - (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: inSection:] atScrollPosition:UITableViewScrollPositionBottom animated:NO];

三、在UITableViewCell上建立多个 UILable ,来代替cell的加载显示

 - (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(, , , )];

   [Datalabel setTag:];

   Datalabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;

   [cell.contentView addSubview:Datalabel];

   [Datalabel release];

  } 

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

  [Datalabel setFont:[UIFont boldSystemFontOfSize:]];

  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];

IOS 中列表的TableView 详解,常用方法整理的更多相关文章

  1. iOS中MVC等设计模式详解

    iOS中MVC等设计模式详解 在iOS编程,利用设计模式可以大大提高你的开发效率,虽然在编写代码之初你需要花费较大时间把各种业务逻辑封装起来.(事实证明这是值得的!) 模型-视图-控制器(MVC)设计 ...

  2. iOS中线程同步基本详解

    为什么使用线程同步技术:多个线程是同时执行的 如果多个线程同时操作一个资源 会造成此资源的数据错乱 线程同步简介 线程同步,多条线程按顺序地访问某个资源 注意:此处的同步不是一起执行的意思 是一个一个 ...

  3. IOS中的NSTimer定时器详解

    /* 在IOS中有多种定时器,这里我对NSTimer定时器做了一个简单的介绍.如果你是小白,你可能会从这篇文章中学习到一些知识,如果你是大牛,请别吝啬你的评论,指出我的不足,你的质疑是对我最大的帮助. ...

  4. iOS中 CoreGraphics快速绘图(详解) 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博 第一步:先科普一下基础知识: Core Graphics是基于C的API,可以用于一切绘图操作 Core Graph ...

  5. iOS中 蓝牙2.0详解/ios蓝牙设备详解 韩俊强的博客

    每日更新关注:http://weibo.com/hanjunqiang  新浪微博 整体布局如下:     程序结构如右图: 每日更新关注:http://weibo.com/hanjunqiang  ...

  6. iOS中UINavigationController控制器使用详解

    一.概述 UINavigationController用来管理视图控制器,在多视图控制器中常用.它以栈的形式管理视图控制器,管理视图控制器个数理论上不受限制(实际受内存限制),push和pop方法来弹 ...

  7. iOS中--NSArray调用方法详解 (李洪强)

    下面的例子以     NSArray *array = [NSArray arrayWithObjects:@"wendy",@"andy",@"to ...

  8. IOS中的网络编程详解

    在移动互联网时代,几乎所有应用都需要用到网络,比如QQ.微博.网易新闻.优酷.百度地图,只有通过网络跟外界进行数据交互.数据更新,应用才能保持新鲜.活力,如果没有了网络,也就缺少了数据变化,无论外观多 ...

  9. IOS中UIActionSheet使用方法详解

    一.初始化方法 - (instancetype)initWithTitle:(NSString *)title delegate:(id<UIActionSheetDelegate>)de ...

随机推荐

  1. ul和dl的区别

    列表中有标题的时候就用dl,没有的话就用ul

  2. nginx配置文件语法高亮显示方法

    1.去官方站点下载nginx.vim http://www.vim.org/scripts/script.php?script_id=1886 2.创建nginx.vim的存放目录 # mkdir - ...

  3. System.DateUtils 1. DateOf、TimeOf 简单修饰功能

    编译版本:Delphi XE7 { Simple trimming functions } // 简单修饰功能 function DateOf(const AValue: TDateTime): TD ...

  4. Eclipse动态web工程(Dynamic Web Project)添加jar文件的正确方法

    Eclipse中,创建了动态web工程之后,如果需要添加新的jar文件,有两种方法.第一种是配置工程的“build path”,第二种则是将jar文件放在工程目录下的“/WebContent/WEB- ...

  5. Chapter 1: Design the application architecture

    1.1 Plan the application layers 提到了repository pattern,SoC(Separation of Concern), 进而提及MVC,Action/Act ...

  6. 【POJ3621】Sightseeing Cows

    Sightseeing Cows Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8331   Accepted: 2791 ...

  7. NTP时间同步服务器设置

    一.Window Server设置 [服务器端设置]1) 修改注册表以下键值:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\ ...

  8. Oracle几个基础配置问题:ORA-12154: TNS: 无法解析指定的连接标识符、ORA-12514: TNS: 监听程序当前无法识别连接描述符中请求的服务、ORA-12516 TNS监听程序找不到符合协议堆栈要求的可用处理程序

    问题1:ORA-12154: TNS: 无法解析指定的连接标识符 在一台服务器上部署了Oracle客户端,使用IP/SID的方式访问,老是报ORA-12154错误,而使用tnsnames访问却没有问题 ...

  9. 委托、回调 Lambda表达式书写方式

  10. IOS开发--自定义segment控件,方便自定义样式

    系统的segment控件太封闭,想换个颜色加个背景太难了,忍不住自己写一个,以备不时之需 这个控件给出了很多自定义属性的设置,用起来还是比较方便的,需要注意的 itemWidth如果不设置,则会按照控 ...