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

[转载]TableView详解的更多相关文章

  1. Java基础 之软引用、弱引用、虚引用 ·[转载]

    Java基础 之软引用.弱引用.虚引用 ·[转载] 2011-11-24 14:43:41 Java基础 之软引用.弱引用.虚引用 浏览(509)|评论(1)   交流分类:Java|笔记分类: Ja ...

  2. [转载]Linux 命令详解:./configure、make、make install 命令

    [转载]Linux 命令详解:./configure.make.make install 命令 来源:https://www.cnblogs.com/tinywan/p/7230039.html 这些 ...

  3. [转载]Apple Watch 开发详解

    Apple Watch 开发详解 Apple Watch现在对于第三方开发者来说更多的还是一块额外的屏幕.暂时WatchKit没有能给出足够的接口.现在Watch App的主要运算逻辑需要依赖iPho ...

  4. (转载)log4net 组件详解

    1.概述 log4net是.Net下一个非常优秀的开源日志记录组件.log4net记录日志的功能非常强大.它可以将日志分不同的等级,以不同的格式,输出到不同的媒介.本文主要是介绍如何在Visual S ...

  5. (转载)UITableView使用详解

    在开发iphone的应用时基本上都要用到UITableView,这里讲解一下UITableView的使用方法及代理的调用情况 UITableView使用详解 - (void)viewDidLoad { ...

  6. tableview 详解I

    在开发iphone的应用时基本上都要用到UITableView,这里讲解一下UITableView的使用方法及代理的调用情况 UITableView使用详解 - (void)viewDidLoad { ...

  7. [转载] 多图详解Spring框架的设计理念与设计模式

    转载自http://developer.51cto.com/art/201006/205212_all.htm Spring作为现在最优秀的框架之一,已被广泛的使用,51CTO也曾经针对Spring框 ...

  8. 【转载】log4j详解使用

    log4j详解 日志论    在应用程序中输出日志有有三个目的:(1)监视代码中变量的变化情况,把数据周期性地记录到文件中供其他应用进行统计分析工作. (2)跟踪代码运行进轨迹,作为日后审计的依据.  ...

  9. 【转载】GitHub详解

    原文:GitHub详解 GitHub详解 GitHub 是一个共享虚拟主机服务,用于存放使用Git版本控制的软件代码和内容项目.它由GitHub公司(曾称Logical Awesome)的开发者Chr ...

随机推荐

  1. c++ 左值右值 函数模板

    1.先看一段代码,这就是一种函数模板的用法,但是红色的部分如果把a写成a++或者写成一个常量比如1,都是编译不过的,因为如果是a++的话,实际上首先是取得a的 值0,而0作为一个常量没有地址.写成1也 ...

  2. JavaScript - 事件流

    事件流 事件冒泡就是事件沿DOM树向上传播,在没一级节点上都会发生,直至传播到document对象. 事件捕获正好相反,但是老版本的浏览器不支持,因此很少有人使用事件捕获. 事件处理程序 HTMl 事 ...

  3. 最实用的APP界面设计知识,有温度的APP设计(转)

    在逛简书的时候,无意之间看到了这样的一篇非常有意思的app设计博文.顾25学堂的摘录了其中的一些关于移动端APP界面设计的精华.分享给25学堂的app设计师们. 当然,下面的这些app设计知识点是来自 ...

  4. 数据库是.frm,.myd,myi备份如何导入mysql (转)

    今天找了个案例,琢磨了半天,才分析大概出来,数据库是.frm,.myd,myi备份,不会导入mysql,到网上找了些资料,导入成功. 首先说一下这几种文件是干什么的,*.frm是描述了表的结构,*.M ...

  5. 在Asp.Net MVC中PartialView与EditorFor和DisplayFor的区别

    相同之处: PartialView, EditorFor 和 DisplayFor 都可以用作来实现页面的公共部分,其他页面可以根据需求来引用. 不同之处: PartialView 是从Page的角度 ...

  6. 遍历windows驱动

    驱动都存在 \\Driver 或者 \\FileSystem 目录对象里 我们只需要遍历这两个目录就可以遍历windows所有驱动 知识点 \\Driver  \\FileSystem (dt _OB ...

  7. 在苹果手机上input有内阴影怎么去除

    一个input中在安卓手机上完全按照自己的样式去展示,但是在苹果手机上发现Input有内阴影,怎么去除内阴影呢? 在input样式中这样添加 #div{ .... appearance:button; ...

  8. 非正规写法获取不到tr,td

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  9. 【设计模式】MVC模式

    MVC 模式代表 Model-View-Controller(模型-视图-控制器) 模式.这种模式用于应用程序的分层开发. Model(模型) - 模型代表一个存取数据的对象或 JAVA POJO.它 ...

  10. MVVM模式下实现拖拽

    在文章开始之前先看一看效果图 我们可以拖拽一个"游戏"给ListBox,并且ListBox也能接受拖拽过来的数据, 但是我们不能拖拽一个"游戏类型"给它. 所以 ...