UITableViewDataSource
来源:互联网 发布:python 建立tcp连接 编辑:程序博客网 时间:2024/06/05 23:54
UITableViewDataSource IOS9.1
需要实现的:
设置每组的行数
- ()NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
设置单元格
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
可选的:
设置组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView;
设置每组的组头文字
- (nullable NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
设置每组的组尾文字
- (nullable NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
设置单元格是否可被编辑
*这里设置了 false ,实现了commitEditingStyle方法,也不会出现左划删除按钮- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
设置单元格是否可被移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;*这个需要tableview处于编辑状态, [_tableView setEditing:true];*记得将当前单元格的数据删除并插入到之后所在位置
设置表单的索引
- (nullable NSArray<NSString *> *)sectionIndexTitlesForTableView:(UITableView *)tableView
处理点击索引的操作
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index *例如:- (NSInteger) tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index{ NSString *key = [keys objectAtIndex:index]; NSLog(@"sectionForSectionIndexTitle key=%@",key); if (key == UITableViewIndexSearch) { [tableView setContentOffset:CGPointZero animated:NO]; return NSNotFound; } return index;}
实现这个方法 可以出现单元格左划删除按钮
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;*如果要删除数据,需要在方法体内再判断,如:- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ NSMutableArray *group =_tableViewDataArr[indexPath.section]; NSMutableDictionary *contact = group[indexPath.row]; if(editingStyle == UITableViewCellEditingStyleDelete){ NSLog(@" 删除单元格 "); [group removeObject:contact]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom]; }}
处理单元格移动操作
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath;*这个需要tableview处于编辑状态,
0 0
- UITableViewDataSource
- UITableViewDataSource
- UITableViewDataSource
- UITableViewDataSource, UITableViewDelegate
- UITableViewDataSource的方法
- UITableView(三)--- UITableViewDataSource
- UITableViewDataSource的代理方法
- 29.UITableViewDataSource详解
- iOS UITableViewDelegate UITableViewDataSource 执行顺序
- id <UITableViewDataSource> dataSource
- 怎样创建表格---UITableView UITableViewDataSource UITableViewDelegate
- 怎样创建表格---UITableView UITableViewDataSource UITableViewDelegate .
- UITableViewDataSource和UITableViewDelegate函数(一)
- UITableViewDataSource 和 UITableViewDelegate协议中常用方法
- Swift UITableView遵从UITableViewDataSource报错问题
- 如何将UITableViewDelegate和UITableViewDataSource从UITableViewController中分离出来?
- 如何将UITableViewDelegate和UITableViewDataSource从UITableViewController中分离出来?
- UITableViewDataSource和UITableViewDelegate内常用的13个方法
- 常用的git语句以及代码托管地址
- 如果机会没有来敲门,那就为自己开一扇门。– 米尔顿‧伯利
- iOS清除缓存
- 151023的测试总结
- 布局Layouts之LinearLayout线性布局
- UITableViewDataSource
- 基于树的堆移除根节点实现排序
- Android 生成含签名文件的apk安装包
- 5.数字
- 关于内部存储和外部存储
- ios 摇一摇功能
- 用SAXReader解析xml文档
- 一键横屏--------纠结了好久
- Xcode常见的快捷键