一、建立 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. Mysql常用命令详解

    Mysql安装目录 数据库目录 /var/lib/mysql/ 配置文件 /usr/share/mysql(mysql.server命令及配置文件) 相关命令 /usr/bin(mysqladmin ...

  2. PHPCMS_v9 wap不同列表采用不同模板的方法

    .在phpcms\modules\wap\index.php中搜索 $template = ($TYPE[$typeid]['parentid']==0 && in_array($ty ...

  3. phpcms调用一级栏目和二级栏目

    {loop subcat(,,,$siteid) $r}  {php $num++} <strong><a href=} <br /> {elseif $n!=$c} | ...

  4. WPF程序最小化到任务通知栏

    我们通常使用的桌面软件,都可以最小化到任务通知栏,并且可以从任务通知栏再打开当前软件,或者通过软件的快捷方式从任务通知栏呼出. 我们可以通过下面的方式把WPF程序最小化到任务栏.由于WPF并没有实现N ...

  5. C++重载覆盖隐藏

    写一个程序,各写出重载覆盖 1 // // main.cpp // 2013-7-17作业2 // // Created by 丁小未 on 13-7-17. // Copyright (c) 201 ...

  6. xcode6 下 ios simulator 有 Home 键么?

    4s之前 ,现在,只能用command+shift+h来代替

  7. 学习linux内核时常碰到的汇编指令(2)

    转载:http://blog.sina.com.cn/s/blog_4be6adec01007xvh.html JNGE∶指令助记符——(有符号数比较)不大于且不等于转移(等价于JL).当SF和OF异 ...

  8. 锤子banner

    查看效果: http://js.jirengu.com/negor/4/edit?html,output <!DOCTYPE html> <html> <head> ...

  9. js 获取系统当前时间

    JS获取当前的日期和时间的方法:var myDate = new Date();myDate.getYear(); //获取当前年份(2位)myDate.getFullYear(); //获取完整的年 ...

  10. position-relative 的问题

    对100%宽度的元素0001添加position-relative属性,如果再给left/right属性,可能会导致0001元素超出其父盒子的范围.如果盒子0001的父级元素是body,可能会出现滚动 ...