UITableView应用1
来源:互联网 发布:阿里云账号登录 编辑:程序博客网 时间:2024/06/05 06:21
一个使用UITableView的实例
self.tableView 是获取整个表格
[self.tableView reloadData]; //刷新表格
UITableView使用的协议有<UITableViewDelegate>和<UITableViewDataSource>
UITableViewDataSource协议中必须要实现的两个方法是
- (NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section; //返回每个区域的行数
- (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath;
//生成单元格,在表格中加载每一个单元格时都会回调这个方法,常用的实现方法是:
{
static NSString* CellIdentifier = @"Cell";//作为单元格重用的唯一标识
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifer:CellIdentifier];
if(cell == nil){
cell = [[[UITableView alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
//其中,UITableViewCellStyle对单元格的内容有四种显示风格,
/*UITableViewCellStyleDefault、UITableViewCellStyleValue1、UITableViewCellStyleValue2、UITableViewCellStyleSubtitle,其中只有后三种才可以显示出单元格的detailTextLabel属性值。*/
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; //设置单元格右边按钮的显示风格,单击右侧按钮,回调的方法是<UITableViewDelegate>协议中的- (void)tableView:(UITableView*)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath*)indexPath方法。
}
//然后就是为单元格cell的textLabel、detailTextLabel属性进行赋值
//然后返回cell
}
下面是<UITableViewDataSource>协议中的一些常用方法:
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView; //返回表格中有几个区域
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section; //返回指定区域的页眉
- (NSString*)tableView:(UITableView*)tableView titleForFooterInSection:(NSInteger)section; //返回指定区域的页脚
- (BOOL)tableView:(UITableView*)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath; //返回指定位置的单元格是否可以编辑
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath; //当单元格进入到编辑模式(插入或者删除),点击插入或者删除按钮调用的方法,来进行更具体的操作。
- (BOOL)tableView:(UITableView*)tableView canMoveRowAtIndexPath:(NSIndexPath*)indexPath; //返回指定位置的单元格是否可以移动
- (void)tableView:(UITableView*)tableView moveRowAtIndexPath:(NSIndexPath*)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath;//将指定位置的单元格移动到另一个位置
下面是<UITableViewDelegate>协议中常用的方法
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath; //返回单元格的高度
- (CGFloat)tableView:(UITableView*)tableView heightForHeaderInSection:(NSInteger)section; //设置指定区域的页眉高度
- (CGFloat)tableView:(UITableView*)tableView heightForFooterInSection:(NSInteger)section; //设置指定区域的页脚高度
- (void)tableView:(UITableView*)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath; //单击单元格指定的方法,一般是实现页面的切换
- (UITableViewCellEditingStyle)tableView:(UITableView*)tableView editingStyleForRowAtIndexPath:(NSIndexPath*)indexPath; //当单击导航栏的左侧按钮时,设置单元格的编辑风格,是插入或者删除
- UITableView应用1
- UITableView 应用及其总结
- 笔记:UITableView应用
- IOS UITableView 基础应用
- iOS uitableview 的应用
- UITableView(初级应用)
- UITableView(高级应用)
- UITableView应用-2A
- UITableView - 1
- 使用 UITableView 创建表格应用演练(1)——一个简单的表格应用
- UITableView 应用(五)UITableView样式的自定义
- [转载]UITableView 应用(五)UITableView样式的自定义
- 【iphone应用开发】UITableView的详细讲解
- iPhone应用开发 UITableView学习点滴详解
- 【iOS开发】 UITableView 理解与应用
- plist文件及UITableView的高级应用
- UITableView的分割线的应用
- UITableView 应用(三)UITableViewDelegate 方法总结
- UIO-用户空间驱动的新发展
- 基于AOP实现权限管理:访问控制模型RBAC和ACL
- hdu 2255 奔小康赚大钱 KM算法
- CF contest/382/B. Number Busters
- 特色项目
- UITableView应用1
- ubuntu13.10 编译安装 wine1.7.10
- STM32F2.02版固件库之二十一(DBGMCU)
- 冒泡排序
- cocos2dx场景切换中init、onEnter、onEnterTransitionDidFinish的调用
- How to: Compile Linux kernel 2.6
- 利用普通的input标签实现获取后台时间再格式化,再进行修改保存
- mysql备忘笔记二(分区技术)
- Python-Project Euler 36