iPhone应用开发 UITableView学习点滴详解是本文要介绍的内容,内容不多,主要是以代码实现UITableView的学习点滴,我们来看内容。

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

iPhone应用开发 UITableView学习点滴详解的更多相关文章

  1. Eclipse IDE for C/C++ Developers和MinGW安装配置C/C++开发学习环境详解

    Eclipse IDE for C/C++ Developers和MinGW安装配置C/C++开发学习环境详解 操作系统:Windows 7 JDK版本:1.6.0_33 Eclipse版本:Juno ...

  2. iOS 开发之照片框架详解

    转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework.html 一. 概要 在 iOS 设备中,照片和视频是相当重 ...

  3. iOS 开发之照片框架详解(2)

    一. 概况 本文接着 iOS 开发之照片框架详解,侧重介绍在前文中简单介绍过的 PhotoKit 及其与 ALAssetLibrary 的差异,以及如何基于 PhotoKit 与 AlAssetLib ...

  4. IE8"开发人员工具"使用详解下(浏览器模式、文本模式、JavaScript调试、探查器)

    来源: http://www.cnblogs.com/JustinYoung/archive/2009/04/03/kaifarenyuangongju2.html 在上一篇文章IE8“开发人员工具” ...

  5. iOS 开发之照片框架详解之二 —— PhotoKit 详解(上)

    转载自:http://kayosite.com/ios-development-and-detail-of-photo-framework-part-two.html 一. 概况 本文接着 iOS 开 ...

  6. Android安卓书籍推荐《Android驱动开发与移植实战详解》下载

    百度云下载地址:点我 Android凭借其开源性.优异的用户体验和极为方便的开发方式,赢得了广大用户和开发者的青睐,目前已经发展成为市场占有率很高的智能手机操作系统. <Android驱动开发与 ...

  7. Java开发利器Myeclipse全面详解

    Java开发利器Myeclipse全面详解: Ctrl+1:修改代码错误 Alt+Shift+S:Source命令 Ctrl+7:单行注释 Ctrl+Shift+/ :多行注释 Ctrl+I :缩进( ...

  8. VirtualBox开发环境的搭建详解(转)

    VirtualBox开发环境的搭建详解   有关VirtualBox的介绍请参考:VirtualBox_百度百科 由于VirtualBox官网提供的搭建方法不够详细,而且本人在它指导下,从下载所需的开 ...

  9. IE8“开发人员工具”使用详解上(各级菜单详解)

    来源: http://www.cnblogs.com/JustinYoung/archive/2009/03/24/kaifarenyuangongju.html IE8“开发人员工具”使用详解上(各 ...

随机推荐

  1. java 配置环境变量

    使用java编程首先需要安装jdk,然后还需要给你的电脑配置环境变量,下面就用图文演示如何配置环境变量: 1.右键我的电脑 -> 属性 2.点击“高级系统设置” 3.点击“环境变量” 4.在系统 ...

  2. BOOL和bool的区别

    一. 1.类型不同 BOOL为int型 bool为布尔型 2.长度不同 bool只有一个字节 BOOL长度视实际环境来定,一般可认为是4个字节 3.取值不同 bool取值false和true,是0和1 ...

  3. QT_BEGIN_NAMESPACE和QT_END_NAMESPACE的作用

    本文根据在网上找到的一些资料总结来的,并加入了一些自己的想法. 在源代码中是这样定义的: # define QT_BEGIN_NAMESPACE namespace QT_NAMESPACE { # ...

  4. php 概率算法(转)

    例:function get_rand($proArr) { $result = ''; //概率数组的总概率精度 $proSum = array_sum($proArr); //概率数组循环 for ...

  5. android 解析XML 工具类

    /** * Created by John on 2016/3/29. */ public class XmlParser { private static final String ns = nul ...

  6. 7月10日——[HouseStark] 扬帆起航--第一次会议

    本次会议为小组成员第一次会议 内容:每个成员提出一个及以上的项目及内容,成员内部商议并投票决定要做的项目 会议时长:90分钟 地点:电三楼8楼816室 成员 项目 讨论结果 崔文祥 高校就业信息汇总网 ...

  7. 也来说说C/C++里的volatile关键字

    去年年底的样子,何登成写了一篇关于C/C++ volatile关键字的深度剖析blog(C/C++ Volatile关键词深度剖析).全文深入分析了volatile关键字的三个特性.这里不想就已有内容 ...

  8. 堆糖瀑布流完整解决方案(jQuery)

    2010年堆糖创办以来,网站界面经历过3-5次重大改版,logo也曾更换过两次,早期蓝红相间三个圈的logo恐怕很少有人记得了.与此同时,前端 js 框架也在默默的更新换代.最早堆糖上线时,js 采用 ...

  9. 《C++primer》v5 第5章 语句 读书笔记 习题答案

    5.1 空语句只有一个";".如果什么也不想做可以使用空语句. 5.2 用花括号{}括起来的叫块,也叫复合语句.有多条语句作用在同一个作用域时,需要用花括号括起来. 5.3 降低了 ...

  10. 每日总结 -----把人家代码干掉了 我恨git

    今天搞了下午git,写完代码commit之后,pull完发现没法push,说是和origin有分支,然后自己查资料又是reset又是rebase的,commit之后发现自己改动的代码几乎没有被提交上去 ...