UITableView 应用及其总结
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 rows 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 应用及其总结的更多相关文章
- iOS UITableView 与 UITableViewController
很多应用都会在界面中使用某种列表控件:用户可以选中.删除或重新排列列表中的项目.这些控件其实都是UITableView 对象,可以用来显示一组对象,例如,用户地址薄中的一组人名.项目地址. UITab ...
- UITableView(二)
#import "ViewController.h" @interface ViewController () @end @implementation ViewControlle ...
- iOS: 在UIViewController 中添加Static UITableView
如果你直接在 UIViewController 中加入一个 UITableView 并将其 Content 属性设置为 Static Cells,此时 Xcode 会报错: Static table ...
- iOS 编辑UITableView(根据iOS编程编写)
上个项目我们完成了 JXHomepwner 简单的应用展示,项目地址.本节我们需要在上节项目基础上,增加一些响应用户操作.包括添加,删除和移动表格. 编辑模式 UITableView 有一个名为 e ...
- 使用Autolayout实现UITableView的Cell动态布局和高度动态改变
本文翻译自:stackoverflow 有人在stackoverflow上问了一个问题: 1 如何在UITableViewCell中使用Autolayout来实现Cell的内容和子视图自动计算行高,并 ...
- iOS - UITableView中Cell重用机制导致Cell内容出错的解决办法
"UITableView" iOS开发中重量级的控件之一;在日常开发中我们大多数会选择自定Cell来满足自己开发中的需求, 但是有些时候Cell也是可以不自定义的(比如某一个简单的 ...
- UITableView cell复用出错问题 页面滑动卡顿问题 & 各杂七杂八问题
UITableView 的cell 复用机制节省了内存,但是有时对于多变的自定义cell,重用时会出现界面出错(例如复用出错,出现cell混乱重影).滑动卡顿等问题,这里只简单敲下几点复用出错时的解决 ...
- UITableview delegate dataSource调用探究
UITableview是大家常用的UIKit组件之一,使用中我们最常遇到的就是对delegate和dataSource这两个委托的使用.我们大多数人可能知道当reloadData这个方法被调用时,de ...
- UITableView点击每个Cell,Cell的子内容的收放
关于点击TableviewCell的子内容收放问题,拿到它的第一个思路就是, 方法一: 运用UITableview本身的代理来处理相应的展开收起: 1.代理:- (void)tableView:(UI ...
- 使用UITableView的分组样式
分组样式顾名思义是对TableView中的数据行进行分组处理,每个分组都有一个header和footer. TableView中header的英文文本是大写的,footer的英文文本是小写的.如下图浅 ...
随机推荐
- Android OptionMenu
1.Java package com.fish.helloworld; import android.app.Activity; import android.content.Context; imp ...
- Django搭建及源码分析(一)
一.关于Django以下两个站点,在使用方面有详细说明. http://www.nowamagic.net/academy/part/13/286 http://www.w3cschool.cc/dj ...
- oracle 数组类型
create or replace function my_test(p_str varchar2) return number as --普通变量 v_var ); --固定长度数组 type v_ ...
- C#中判断文件夹中存在某个txt文本
strFileName="D:\\strarray.txt"; if (File.Exists(strFileName))//判断文件是否存在 { }
- 整理一些有意思的php笔试题
慢慢补充 1.下面这段代码的输出是什么: $a = in_array('01', array('1'))==var_dump('01'==1); echo $a; 说明:in_array('01', ...
- js中forEach无法跳出循环?
1. forEach() forEach() 方法从头至尾遍历数组,为每个元素调用指定的函数.如上所述,传递的函数作为forEach()的第一个参数.然后forEach()使用三个参数调用该 函数:数 ...
- postgresql 入门(含java、scala连接代码)
1.下载安装包 官网:http://www.postgresql.org/download/ 按自己需求,下载安装包, 我下载的windows版32位的.http://get.enterprisedb ...
- Linux rabbitmq的安装和安装amqp的php插件
RabbitMQ是一个消息代理.它的核心原理非常简单:接收和发送消息.你可以把它想像成一个邮局:你把信件放入邮箱,邮递员就会把信件投递到你的收件人处.在这个比喻中,RabbitMQ是一个邮箱.邮局.邮 ...
- 二,CentOS minimal 网络配置及用yum安装所需软件
CentOS minimal在刚安装完成后,ifconfig一下没发现网卡,是因为使用最小安装的网卡默认没启动,设置配置文件很简单,如下: 1.打开配置文件 vi /etc/sysconfig/net ...
- PHP截取字符串 兼容utf-8 gb2312
<?php function subString($string,$length,$append = false) { if(strlen($string) <= $length ) { ...