UITableView中的DataSource和delegate
来源:互联网 发布:怎样进入淘宝店铺 编辑:程序博客网 时间:2024/06/16 09:38
1,顾名思义,dataSource意思为数据源,delegate意为代理,其内部包含很多方法。
UITableView需要显示数据,则数据源(datasource)可以给他提供数据从而显示出来,其会向数据源查询一共有多少行数据以及显示什么数据等,如果没有设置数据源的,那么UITableView就不会产生任何数据,没有作用。同时,遵守UITableViewDataSource协议的都可以是数据源,所以添加协议从而提供数据源。
同时UITableView也要设置对象,以防在UITableView触发事件时可以做出处理,比如选中某一行和某一列。遵守UITableViewDataSource协议的都可以是代理对象。
2,上边提到的UITableViewDataSource 协议中常用方法:
(1.)设置右边索引值
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
(2.)设置分组标识
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
(3.)设置分组个数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
(4.)设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
(5.)创建cell(使用重用机制,如下例)
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
(6.)设置tableView的每一行的编辑状态(YES,可编辑)
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES
}
(7.)edit按钮的点击事件(当点击edit按钮时触发)
- (void)setEditing:(BOOL)editing animated:(BOOL)animated
(8.)当提交编辑操作时触发
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
(9.)设置tableView每一行是否允许移动(YES,可移动)
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES
}
(10.)提交移动操作之后触发
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
3,UITableViewDelegate协议中常用方法
(1).设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 55;
}
(2).选中cell时触发
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
(3.)设置tableViewCell的编辑样式(插入/删除)
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
(4.)设置当点击编辑按钮时上面显示的文字,如显示删除
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0) { return @"删除"; }
(5).设置cell移动的位置
- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath
- UITableView中的DataSource和delegate
- UITableView的数据源(dataSource)和代理(delegate)
- 分离 UITableView 的 Delegate 和 Datasource
- 学习笔记-UITableView的数据源(dataSource)和代理(delegate)
- 学习笔记-UITableView的数据源(dataSource)和代理(delegate)
- tableview中的delegate、DataSource原理
- Core Plot中DataSource和Delegate
- iOS Controller 瘦身运动之 UItableView datasource 与 delegate的分离
- iOS tableview的delegate和datasource执行顺序
- UICollectionView: DataSource and Delegate
- (作业)TableView、Delegate、DataSource
- UITableView的数据源(dataSource)
- UITableView——dataSource
- Datasource 与 Delegate的对比
- NSURLConnection和UITableView的delegate执行先后问题的解决方法
- C#中的delegate和event
- C#中的delegate和event
- C#中的delegate和event
- javascript变量声明提升(hoisting)
- telnet 使用smtp发送邮件
- android.database.sqlite.SQLiteException: no such table解决方法
- iOS动画效果和实现
- java 引用数据类型
- UITableView中的DataSource和delegate
- Windows常用系统函数
- c++第三次作业
- WEB服务框架--CXF简介
- 详解 Objective-C 中的 Runtime(上)
- empty()与remove([expr])
- 因子分解机FM原理及SGD训练
- FileStream写的6,reader自然而然了。
- 我的第一篇blog