iPhone开发应用中关于UITableView详细教程
来源:互联网 发布:中商惠民员工被优化 编辑:程序博客网 时间:2024/04/28 05:26
2011-08-15 13:44 佚名 互联网 我要评论(0) 字号:T | T
本文主要是来学习UITableView的详细操作。UITableView是一个很强大的控件,在我们iphone开发过程中会经常用到。
AD:
iPhone开发应用中关于UITableView详细教程是本文要介绍的内容,主要是来学习UITableView的详细操作。UITableView是一个很强大的控件,在我们iphone开发过程中会经常用到。
下面我做以下简单介绍
UITableView有一个基本元素的索引NSIndexPath,你可以通过索引NSIndexPath找到UITableView下面的子元素只要这个方法
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- //在这个方法里你可以根据NSIndexPath判断相应的元素,然后做处理
例如:
- - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
- {
- if(indexPath.section == 5 && indexPath.row ==2)return;
- }
- UITableView的每一个子元素(Entity)称为UITableViewCell,UITableViewCell由下面这个方法初始化
- -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
- //这个方法是必需的,他是产生UITableView内容的必须载体
例如:
- -(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath
- {//因为UITableView由很好的内存控制机制,他每次只加载一屏幕的cell(7个左右),当用户触摸移动时,动态加载新产生的cell
- static NSString *RootViewControllerCell =@"HelpViewControllerCell";//产生一个静态标识
- UITableViewCell* cell =(UITableViewCell*)[tableViewdequeueReusableCellWithIdentifier:RootViewControllerCell];//标记新产生的cell
- if(cell==nil) //如果cell不为空标识cell还没有被释放,还在屏幕中显示
- {
- cell =[[[UITableViewCellalloc]initWithStyle:UITableViewCellSeparatorStyleSingleLinereuseIdentifier:RootViewControllerCell]autorelease];
- }
- return cell;
- }
UITableViewCell通过NSIndexPath索引,正如上面所看到的,NSIndexPath索引由两个属性section和row
section通常就是我们所谓的段,row所谓的段内的行
我们可以通过下面这个方法返回你想要在UITableView中显示段数
- - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; //通常情况下我们看到的都是一段,左移这个方法不是必须的
我们可以通过下面这个方法返回你想要在UITableView中的某一段中显示的行数
- - (NSInteger)tableView:(UITableView *)tView numberOfRowsInSection:(NSInteger)section;//通常情况下是一段,所以不必判断段数
假如您有很多段,而且每一个段的显示行数还不一样,你就要通过上面的方法精确控制,例如:
- - (NSInteger)tableView:(UITableView *)tView numberOfRowsInSection:(NSInteger)section {
- if(section == 0) return 1;
- if(section == 1) return 1;
- if(section == 2) return 8;
- if(section == 3) return 1;
- if(section == 4 || section ==5) return 3;
- if(section == 6)return 4;
- return0;
- }
这个方法时必须的。
另外我们可以通过下面这个方法精确控制某一行的高度
- - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
- if(indexPath.section == 0 && indexPath.row ==0) return80;
- return 40.0;
- }
另外我们可以通过下面这个方法精确控制某一段的高度
- - (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
- {
- if (section == 0)return60.0;
- return40.0;
- }
另外我们还可以通过下面这个方法精确控制某一段的标题和视图
- - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
- - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
0 0
- iPhone开发应用中关于UITableView详细教程
- iPhone开发应用中关于UITableView详细教程
- iPhone开发应用中关于UITableView详细教程
- 【iphone应用开发】UITableView的详细讲解
- 【iphone应用开发】iphone应用开发之六:UITableView的详细讲解(一)
- 转载【iphone应用开发】iphone应用开发之六:UITableView的详细讲解(一)
- 【iphone应用开发】iphone应用开发之六:UITableView的详细讲解(一)
- 【iphone应用开发】iphone应用开发之六:UITableView的详细讲解(一)
- iPhone开发应用中关于CFRunLoop学习
- iphone应用开发之六:UITableView的详细讲解(一)
- iPhone应用开发 UITableView学习点滴详解
- 微信小应用详细开发教程
- iPhone开发 UITableView 详解
- iPhone开发--uitableview
- iPhone开发之UITableView简单应用(5)
- 【iphone应用开发】UIColor的详细讲解
- 【iphone应用开发】UIWebView的详细讲解
- 【iphone应用开发】NSArray的详细讲解
- 一维加噪信号的平滑处理(2)
- JDK源码研究PriorityQueue(优先队列)
- 批处理解决实际问题1——将目录下所有文件(*.cpp)分别创建同名文件夹并移入其中
- Java环境变量配置
- uva 11584 Partitioning by Palindromes | dp
- iPhone开发应用中关于UITableView详细教程
- hdu 2601 An easy problem
- hdu2544 最短路
- Android学习笔记(一)
- ClassLoader解读
- IOS请求WEB应用的方法
- 简谈设计模式的几个原则
- 通过分析 JDK 源代码研究 TreeMap 红黑树算法实现
- 关于warp中遇到Branch Divergence的执行情况