一、建立 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++ 基础 const放在函数末尾的意思

  2. hibernate查询语句实例代码

    一.聚集函数的使用: avg(...), sum(...), min(...), max(...) count(*) count(...), count(distinct ...), count(al ...

  3. Linux环境下stl库使用(vector)

    step1: #include <iostream> #include <vector> #include <string> using namespace std ...

  4. oracle限制ip訪問

    我這oracle版本為11.2.0.4,裝的GRID,所以在grid用戶下編輯sqlnet.ora 1.cd  /grid/product/11.2.0/network/admin 2.編輯sqlne ...

  5. phpcms-v9系统搭建wap网站及单页面

    如需要绑定域名为wap.domain.com,作下如操作: 一.把wap.domain.com域名绑定到你的这个网站主机上. 二.在网站后台——模块——手机门户域名里面填写“http://wap.do ...

  6. Android 开发工具之Codota

    Codota 的特性 的确,正如codota 官方所说,的确是精品,他的搜索源,不仅只有Github,而且还有知名博客和开发者网站,让你搜索一个东西,不用在找上半天: 除了搜索功能,首页的下方还罗列比 ...

  7. 使用while代替for循环的几个习题

    1:兔子问题 2:100以内质数的和 3:单位给发了一张150元购物卡,拿着到超市买三类洗化用品.洗发水15元,香皂2元,牙刷5元.求刚好花完150元,有多少种买法,没种买法都是各买几样? 总结:wh ...

  8. spring实例教程

    1.配置好spring mvc发现访问无法匹配,很可能是文件放的位置或者相对目录不对. 2.实例大全:http://www.yiibai.com/spring/spring-collections-l ...

  9. C语言常用知识

    跳出for循环主要有以下2中方式: 1.用break语句.如: int i; for(i=0; i<10; i++) {     if(i>3)    // 如果i>3,跳出for循 ...

  10. 使用JdbcTemplate报 Incorrect column count: expected 1, actual 5错误解决

    Incorrect column count: expected 1, actual 5 在使用jdbc的querForObject queryForList的时候,出现Incorrect colum ...