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的英文文本是小写的.如下图浅 ...
随机推荐
- ASP.NET中的Eval与DataBinder.Eval()方法
1.bind是一种双向数据绑定,有数据源时才会有改变. 2..net1.x版本中有DataBinder(Container.DataItem,"数据项") 单向数据绑定 .net ...
- iOS 获取当前城市
1.倒入头文件 #import <CoreLocation/CoreLocation.h> 2.实现定位协议CLLocationManagerDelegate 3.定义定位属性 @pro ...
- Objective-C介绍
概述 2007年苹果公司推出了Objective—C 2.0,它是Mac OS X和iOS开发的基础语言.
- string,stringbuilder,stringbuffer
String可以储存和操作字符串,即包含多个字符的字符数据.这个String类提供了存储数值不可改变的字符串. StringBuilder是线程不安全的,运行效率高,如果一个字符串变量是在方法里面定义 ...
- mysql 5.7压缩包安装笔记
转载请注明出处http://www.cnblogs.com/havedream/p/5075263.html 重装系统之后准备安装mysql,看到官网上有mysql 5.7.10可以下载就点了,然后就 ...
- [译]Memory Reordering Caught in the Act
原文:http://preshing.com/20120515/memory-reordering-caught-in-the-act/ 编写lock-free的C/C++程序时,在保证memory ...
- 3种方式实现Java多线程
java中实现多线程的方法有两种:继承Thread类和实现runnable接口. 1.继承Thread类,重写父类run()方法 public class thread1 extends Thread ...
- linux中文显示乱码的解决办法
linux中文显示乱码的解决办法 linux中文显示乱码是一件让人很头疼的事情. linux中文显示乱码的解决办法:[root@kk]#vi /etc/sysconfig/i18n将文件中的内容修改为 ...
- MapReduce shuffle阶段详解
在Mapreduce中,Shuffle过程是Mapreduce的核心,它分布在Mapreduce的map阶段和reduce阶段,共可分为6个详细的阶段: 1).Collect阶段:将MapTask的结 ...
- expr命令
expr命令的兩大作用:1)四则运算:2)字符串的操作: 1.四则运算 [tough@localhost ~]$ + + [tough@localhost ~]$ + [tough@localhost ...