10.UITableView的刷新数据方法
来源:互联网 发布:单片机怎么学 编辑:程序博客网 时间:2024/05/21 18:39
数据刷新方法
- 重新刷新屏幕上的所有cell
[self.tableView reloadData];
- 刷新特定行的cell
[self.tableView reloadRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:0 inSection:0],[NSIndexPath indexPathForRow:1 inSection:0]]withRowAnimation:UITableViewRowAnimationLeft];
- 插入特定行数的cell
[self.tableView insertRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:0 inSection:0],[NSIndexPath indexPathForRow:1 inSection:0]] withRowAnimation:UITableViewRowAnimationLeft];
- 删除特定行数的cell
[self.tableView deleteRowsAtIndexPaths:@[ [NSIndexPath indexPathForRow:0 inSection:0],[NSIndexPath indexPathForRow:1 inSection:0] ]withRowAnimation:UITableViewRowAnimationLeft];
数据刷新的原则
- cell的个数与模型的个数一定要相等。
- 通过修改模型数据,来修改tableView的展示
- 先修改模型数据
- 再调用数据刷新方法
- 不要直接修改cell上面子控件的属性
数据更新操作
若要处理滑动单元格时单元格的编辑模式需要实现TableView代理方法
1./** * 只要实现这个方法,左划cell出现删除按钮的功能就有了 * 用户提交了`添加`(点击了添加按钮)\`删除`(点击了删除按钮)操作时会调用 */- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ if (editingStyle == UITableViewCellEditingStyleDelete) { // 点击了“删除”// 删除模型[self.deals removeObjectAtIndex:indexPath.row];// 刷新表格[self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // 点击了+ NSLog(@"+++++ %zd", indexPath.row); }}/** * 这个方法决定了当tableView处于编辑模式时,每一行的编辑类型:insert(+按钮)、delete(-按钮) */- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return indexPath.row % 2 == 0? UITableViewCellEditingStyleInsert : UITableViewCellEditingStyleDelete;}2. // 设置tableView的编辑模式 [self.tableView setEditing:YES animated:YES]; //当设置tableView处于编辑模式时,默认情况下cell处于UITableViewCellEditingStyleDelete模式。
UITableView的数据批量操作
- UITableView的默认批处理模式
设置如下:
- (void)viewDidLoad { [super viewDidLoad]; // 允许在编辑模式进行多选操作 self.tableView.allowsMultipleSelectionDuringEditing = YES;}//批量操作点击- (IBAction)multiOperation:(id)sender {[self.tableView setEditing:!self.tableView.isEditing animated:YES];}//批量删除处理- (IBAction)remove {// 获得所有被选中的行NSArray *indexPaths = [self.tableView indexPathsForSelectedRows];//遍历所有的行号//注意:数组不可以一边遍历一边做删除操作NSMutableArray *deletedDeals = [NSMutableArray array];for (NSIndexPath *path in indexPaths) {[deletedDeals addObject:self.deals[path.row]];}// 删除模型数据[self.deals removeObjectsInArray:deletedDeals]; // 刷新表格 一定要刷新数据[self.tableView reloadData];}
0 0
- 10.UITableView的刷新数据方法
- UITableView刷新单行数据的方法
- UITableView刷新单行数据的方法
- [IOS]UITableView刷新一个分组的数据
- UITableView刷新数据reLoadData
- UITableView刷新数据
- UITableView + UIAlertView + 数据刷新
- UITableView数据刷新
- uitableview 数据刷新
- iOS UITableView数据刷新
- UI021---UITableView数据刷新
- UITableView刷新数据reLoadData
- UITableView刷新数据reLoadData
- UITableView表格数据刷新
- iphone开发 UITableView数据刷新
- uitableview上提刷新数据
- coredata 自动化刷新uitableview数据
- UITableView的刷新
- POJ3628 01背包
- C 语言资源大全中文版
- Codeforces Round #338 (Div. 2) C. Running Track
- C++中引用和指针的区别
- html转pdf,jsf实现下载功能
- 10.UITableView的刷新数据方法
- 使用消息队列的10个理由
- Ecplise-SVN插件异常: 由于目标计算机积极拒绝,无法连接。
- 渗透测试windows 必备支持
- 关于接口的一些概念性整理
- java基础巩固笔记(3)-类加载器
- 【JZOJ 4353】distance
- HDU-2035
- java基础巩固笔记(4)-代理