一、创建一个列表,不管代码还是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. CocoaPods创建私有pods

    由于项目需求,需要把项目的不同模块拆分出来即 组件化 ,一开始想做成多target模式,后来换成私有pods CocoaPods的安装和使用,网上很多,自行搜索即可. 听说可以基于svn创建pod私有 ...

  2. jsp中查询条件的回显

    后台框架为ssh,前台纯手写无框架是最老的写法,因为是接手别人的项目无法改变框架原型,只能基于修改. 进入正题: 我这里查询条件有两种input的text(文本框)和select(下拉框). 1.te ...

  3. (转) Playing FPS games with deep reinforcement learning

    Playing FPS games with deep reinforcement learning 博文转自:https://blog.acolyer.org/2016/11/23/playing- ...

  4. 手把手写一个html_json信息源

    html_json用于从网页里提取json数据. 这里用新浪读书的书讯举个例子,手把手写一个html_json信息源. 打开新浪读书的首页,可以看到页面下方有最新.书讯.童书.小说等几个Tab,这里我 ...

  5. 远程调试js注意事项

    1:使用host切换工具,先注释掉93服务器的地址,打开链接,点击高级选项,进去后登陆账号密码(如果不行重启浏览器): 2:进入后,增加93服务器上的host地址,重启浏览器,css样式生效: 3:使 ...

  6. case when

    SELECT * FROM  category  WHERE EXISTS (SELECT * FROM goods WHERE goods.cat_id = category.cat_id) cat ...

  7. Python爬虫入门

    Python爬虫简介(来源于维基百科): 网络爬虫始于一张被称作种子的统一资源地址(URLs)列表.当网络爬虫访问这些统一资源定位器时,它们会甄别出页面上所有的超链接,并将它们写入一张"待访列表",即 ...

  8. PHP+Mysql+jQuery实现地图区域数据统计-展示数据

    我们要在地图上有限的区块内展示更多的信息,更好的办法是通过地图交互来实现.本文将给大家讲解通过鼠标滑动到地图指定省份区域,在弹出的提示框中显示对应省份的数据信息.适用于数据统计和地图区块展示等场景. ...

  9. Gulp安装及配合组件构建前端开发一体化

    原文:http://www.dbpoo.com/getting-started-with-gulp/ 所有功能前提需要安装nodejs(本人安装版本v0.10.26)和ruby(本人安装版本1.9.3 ...

  10. Hibernate5.2之一对一外键关联(五)

                                                     Hibernate5.2之一对一外键关联(五) 一.简介 上篇文章中笔者介绍了Hibernate关联关 ...