一、创建一个列表,不管代码还是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. java读取properties文件工具

    public class PropertiesUtil { public static String get(String filePath, String key) { String val = n ...

  2. 初涉hash

    今天和朋友讨论一个问题 有两百亿个数,我给出一个数,找到这两百亿个数中两数相加等于它的组合.要求时间复杂度为线性,空间2G 解决思路是开一个hash表比如a[1000]将所有数存入hash表中,a[i ...

  3. https/相对路径,绝对路径

    1. htttps HTTPS(全称:Hyper Text Transfer Protocol over Secure Socket Layer),是以安全为目标的HTTP通道,简单讲是HTTP的安全 ...

  4. 《java编程思想》读书笔记(一)开篇&第五章(1)

    2017 ---新篇章  今天终于找到阅读<java编程思想>这本书方法了,表示打开了一个新世界. 第一章:对象导论 内容不多但也有20页,主要是对整本书的一个概括.因为已经有过完整JAV ...

  5. quick sort 的简化实现

    Pivot 随机选取意义不大 第一种方法使用随机pivot,使得尽可能平均二分序列,而实际上一般来说需要排序的集合往往是乱序的,无需重新生成随机数作为pivot,大可使用固定位置的数作为pivot,这 ...

  6. [BZOJ 3682]Phorni

    后缀平衡树的模板题? I'm so weak…… 现在觉得替罪羊树比 treap 好写,是不是没救了喵- #include <cstdio> #include <cmath> ...

  7. linux find命令

    Linux中find常见用法示例 ·find   path   -option   [   -print ]   [ -exec   -ok   command ]   {} \; find命令的参数 ...

  8. photoshop,黑白转彩色单色

    方法一: 打开 色相/饱和度 面板,勾选上 着色, 然后调节 明度 滑块. 方法二: 前面方法的缺点是会将修改直接塌陷到图层,如果想不塌陷,可以使用色相蒙板: 同样勾选 着色

  9. Window.Open详解

    文章来源:http://www.cnblogs.com/stswordman/archive/2006/06/02/415853.html 一.window.open()支持环境:JavaScript ...

  10. JDK、JRE、JVM

    首先来说一下JDKJDK(Java Development Kit) 是 Java 语言的软件开发工具包(SDK).JDK是整个JAVA的核心,包括了Java运行环境(Java Runtime Env ...