Plain:

Grouped:

Cell的结构图:

UITableViewCellStyleDefault:预设使用这种,若左侧ImageView没图的话,只有一行字(textLable.text)。

UITableViewCellStyleValue1:左侧为textLable.text并且左对齐,右侧为detailTextLable.text并且右对齐。

UITableViewCellStyleValue2:左侧为detailTextLable.text,右侧为textLable.text并且左对齐。

UITableViewCellStyleSubtitle:跟UITableViewCellStyleDefault大致相同,detailTextLable.text出现在textLable.text下方。

如何使用:

    - (void)dealloc
{
[itemsArray release];
[super dealloc];
} - (void)viewDidLoad
{
[super viewDidLoad]; //初始化资料阵列,待会使用
NSMutableArray *itemsArray = [[NSArray alloc] initWithObjects:@"row 1",@"row 2",@"row 3",nil]; } #pragma mark - Table view data source - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{ // Return the number of sections.
// 告诉tableView总共有多少个section需要显示
return ;
} - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{ // Return the number of ro​​ws in the section.
// 告诉tableView一个section里要显示多少行
return [itemsArray count];
} - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//cell的标饰符
static NSString *CellIdentifier = @"cellIdentifier"; //指定tableView可以重用cell,增加性能,不用每次都alloc新的cell object
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; //如果cell不存在,从预设的UITableViewCell Class里alloc一个Cell object,应用Default样式,你可以修改为其他样式
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
} // Configure the cell... //每一行row进来都判定一下,分别依次选用不同的图片
switch (indexPath.row) {
case :
{
cell.imageView.image = [UIImage imageNamed:@"image0.png"];
}
break;
case :
{
cell.imageView.image = [UIImage imageNamed:@"image1.png"];
}
break;
case :
{
cell.imageView.image = [UIImage imageNamed:@"image2.png"];
}
break;
default:
{
cell.imageView.image = [UIImage imageNamed:@"default.png"];
}
break;
} //其他相同的属性一并设定
cell.textLabel.text = [itemsArray objectAtIndex:indexPath.row];
[cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; //设字体、颜色、背景色什么的
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.detailTextLabel.backgroundColor = [UIColor clearColor];
cell.textLabel.textColor = [UIColor colorWithRed:54.0/255.0 green:161.0/255.0 blue:219.0/255.0 alpha:];
cell.detailTextLabel.textColor = [UIColor colorWithRed:135.0/255.0 green:135.0/255.0 blue:135.0/255.0 alpha:]; //设定textLabel的最大允许行数,超过的话会在尾未以...表示
cell.textLabel.numberOfLines = ; return cell;
} //这个是非必要的,如果你想修改每一行Cell的高度,特别是有多行时会超出原有Cell的高度!
-(CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 85.0;
}

如果比较进阶一点的,想修改或者增加更多的component进去Cell里面,有两种方法(大同小异):
第一种是在cellForRowAtIndexPath delegate method里alloc cell时在contentView里面addSubView。

第二种是需要继承Cell作一个Custom Cell 的Class,并可以使用layoutSubview等方法来修改component的frame呢。

http://blog.csdn.net/titer1991/article/details/7945127

UITableView 应用及其总结的更多相关文章

  1. iOS UITableView 与 UITableViewController

    很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...

  2. UITableView(二)

    #import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...

  3. iOS: 在UIViewController 中添加Static UITableView

    如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...

  4. iOS 编辑UITableView(根据iOS编程编写)

    上个项目我们完成了 JXHomepwner 简单的应用展示,项目地址.本节我们需要在上节项目基础上,增加一些响应用户操作.包括添加,删除和移动表格. 编辑模式 UITableView 有一个名为  e ...

  5. 使用Autolayout实现UITableView的Cell动态布局和高度动态改变

    本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...

  6. iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法

    "UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...

  7. UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题

    UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...

  8. UITableview delegate dataSource调用探究

    UITableview是大家常用的UIKit组件之一,使用中我们最常遇到的就是对delegate和dataSource这两个委托的使用.我们大多数人可能知道当reloadData这个方法被调用时,de ...

  9. UITableView点击每个Cell,Cell的子内容的收放

    关于点击TableviewCell的子内容收放问题,拿到它的第一个思路就是, 方法一: 运用UITableview本身的代理来处理相应的展开收起: 1.代理:- (void)tableView:(UI ...

  10. 使用UITableView的分组样式

    分组样式顾名思义是对TableView中的数据行进行分组处理,每个分组都有一个header和footer. TableView中header的英文文本是大写的,footer的英文文本是小写的.如下图浅 ...

随机推荐

  1. Hadoop的shell脚本分析

    你会发现hadoop-daemon.sh用于启动单独的本机节点 而hadoop-daemons.sh 会批量的ssh到别的机器启动 前记: 这些天一直学习hadoop,学习中也遇到了许多的问题,主要是 ...

  2. myeclipse关闭properties文件自动转义

    1.如图,源代码是这样: 2.保存后重新打开变成这样: 3.解决方法如下:

  3. 当局部变量遇上全局变量——extern及花括号用法举例

    请阅读以下代码并说出它的输出结果. #include <stdio.h> ; int foo() { ; { extern int val; printf("val_foo = ...

  4. 二,CentOS minimal 网络配置及用yum安装所需软件

    CentOS minimal在刚安装完成后,ifconfig一下没发现网卡,是因为使用最小安装的网卡默认没启动,设置配置文件很简单,如下: 1.打开配置文件 vi /etc/sysconfig/net ...

  5. Qt使用默认浏览器打开网页

    #include <QDesktopServices> #include <QUrl> QDesktopServices::openUrl(QUrl("http:// ...

  6. C++ string 转 char*

    string 转到 char* char name[20]; string sname=GatherName[n]; strcpy(name,sname.c_str());

  7. 用jquery循环map

    前些天记录了java中for循环取map,发现用jquery的each一样可以取map(我称之为js的map,不要较劲),且顺序和map中顺序一致.废话少说,看代码 1 2 3 4 5 6 7 8 9 ...

  8. JDBC基础一

    JDBC:java database connectivity SUN公司提供的一套操作数据库的标准规范. JDBC与数据库驱动的关系:接口与实现的关系. JDBC规范(掌握四个核心对象): Driv ...

  9. Oracle 11g 执行计划管理1

    1. 执行计划管理的工作原理 1.1控制执行计划的稳定性 11g之前,可以使用存储大纲(stored outline)和SQL Profile来固定某条SQL语句的执行计划,防止由于执行计划发生变化而 ...

  10. Kafka入门学习(一)

    ====常用开源分布式消息系统 *集群:多台机器组成的系统叫集群. *ActiveMQ还是支持JMS的一种消息中间件. *阿里巴巴metaq,rocketmq都有kafka的影子. *kafka的动态 ...