数据源方法和委托方法
来源:互联网 发布:jar软件下载平台 编辑:程序博客网 时间:2024/04/29 15:58
数据源方法和委托方法
表视图的继承自UIScrollView,这样的继承关系使得表视图可以实现上、下滚动,它的父类,我们将在后面的课程中再次提及
数据源方法(UITableViewDatasource): 实例化表视图时,必须要实现它的数据源方法,以此来完成表中数据的配置(一般来说数据源方法是用来配置表中的数据)
委托方法(UITableViewDelegate): 表视图的委托方法(代理方法),一般是处理表视图基本样式(单元格的高度)以及捕捉选中单元格选中事件等
表示视图调用顺序—委托方法
创建和配置表视图的顺序
创建表视图实例,初始化风格和大小
设置数据源方法和委托方法 开始调用数据源方法,(注意事件循环没有结束)
调用顺序:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // 1,默认为1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; // 2
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; // 3
常用数据源方法和委托方法
常用数据源方法
// 配置section中含有行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
// 创建单元格实例
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
@optional
// 配置表视图section个数,默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
// section中的头部视图的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
// section中的尾部视图的标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
/* 表视图的编辑 移动、删除等 */
// 指定单元格是否支持编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath;
// 指定单元格是否支持移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath*)indexPath;
// 用户编辑了哪一个单元格,在这里执行删除操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath*)indexPath;
// 实现此方法,移动单元格
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
常用委托方法
// 配置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
// 设置section 头部、尾部视图的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
// 自定义section头部、尾部视图,注意:需要指定高度
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
// 用户单击单元格中辅助按钮时,调用该方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
// 用户单击单元格,调用该方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
// 取消单元格时,调用该方法
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
// 设置单元格编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
表视图的继承自UIScrollView,这样的继承关系使得表视图可以实现上、下滚动,它的父类,我们将在后面的课程中再次提及
数据源方法(UITableViewDatasource): 实例化表视图时,必须要实现它的数据源方法,以此来完成表中数据的配置(一般来说数据源方法是用来配置表中的数据)
委托方法(UITableViewDelegate): 表视图的委托方法(代理方法),一般是处理表视图基本样式(单元格的高度)以及捕捉选中单元格选中事件等
表示视图调用顺序—委托方法
创建和配置表视图的顺序
创建表视图实例,初始化风格和大小
设置数据源方法和委托方法 开始调用数据源方法,(注意事件循环没有结束)
调用顺序:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView; // 1,默认为1
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section; // 2
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath; // 3
常用数据源方法和委托方法
常用数据源方法
// 配置section中含有行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
// 创建单元格实例
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
@optional
// 配置表视图section个数,默认为1
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
// section中的头部视图的标题
- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section;
// section中的尾部视图的标题
- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section;
/* 表视图的编辑 移动、删除等 */
// 指定单元格是否支持编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath*)indexPath;
// 指定单元格是否支持移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath*)indexPath;
// 用户编辑了哪一个单元格,在这里执行删除操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath*)indexPath;
// 实现此方法,移动单元格
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;
常用委托方法
// 配置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath;
// 设置section 头部、尾部视图的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section;
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section;
// 自定义section头部、尾部视图,注意:需要指定高度
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section;
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section;
// 用户单击单元格中辅助按钮时,调用该方法
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath;
// 用户单击单元格,调用该方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;
// 取消单元格时,调用该方法
- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath NS_AVAILABLE_IOS(3_0);
// 设置单元格编辑样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath;
0 0
- 数据源方法和委托方法
- 方法、事件和委托
- 委托和方法
- 委托和数据源
- swift__UITableView 的数据源方法 和 代理方法
- 关于委托,事件和方法
- 委托方法
- 委托方法
- CollectionView的委托和数据源
- c# 多播委托 和匿名方法
- 委托和方法的异步调用
- 委托和匿名方法的使用
- C#中委托和方法学习心得
- 委托和匿名方法、lambda表达式
- C#委托的BeginInvoke和EndInvoke方法
- 【C#】Func委托类型和匿名方法
- 委托和方法的异步调用
- 委托中的匿名方法和lambda表达式
- 九度OJ 题目1077:最大序列和
- 单元格的基本用法
- Swift-闭包简单使用
- 深入理解JavaScript系列(43):设计模式之状态模式
- hdoj最短路径问题
- 数据源方法和委托方法
- UVA 1658 - Admiral (拆点+最小费用流)
- 求斐波那契数列O(logn算法)
- 如何理解 servlet 的单实例多线程
- 深入理解JavaScript系列(44):设计模式之桥接模式
- metaq入门部署到实战
- 用SourceTree轻松Git项目图解
- 定制单元格
- hdoj 2899 Strange fuction