tableView的编辑
来源:互联网 发布:重庆大学网络教育专科 编辑:程序博客网 时间:2024/05/16 05:38
// 创建tableView控件
// 在tableView中添加barButton
self.navigationItem.rightBarButtonItem = self.editButtonItem;
// 重写系统的编辑按钮点击方法
- (void)setEditing:(BOOL)editing animated:(BOOL)animated { // 重写方法前要继承 [super setEditing:editing animated:animated]; [self.tableView setEditing:editing animated:YES];}
// 设置哪些行可以进行编辑
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {}
// 设置编辑按钮样式
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { return UITableViewCellEditingStyleDelete;}
// 删除数据
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { // 删除数据源 [self.array removeObjectAtIndex:indexPath.row];// [self.tableView reloadData]; // 通过tableView删除上面的cell // 第一个参数:指定删除哪个分区的行 // 第二个参数:删除的动画效果 [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft]; }}
// 修改删除按钮标题
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath { return @"我看你敢删";}
// 这个方法是iOS8.0之后出现的方法,可以再编辑状态下出现多个按钮
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { // 按钮的点击所触发的事件,都是写在block中的 NSLog(@"测试删除"); }]; deleteAction.backgroundColor = [UIColor lightGrayColor]; UITableViewRowAction *upAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"置顶" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"测试置顶"); }]; upAction.backgroundColor = [UIColor cyanColor]; return @[deleteAction, upAction];}
// 移动
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { // 1.先获取到起始位置的数据 NSString *str = [self.array[sourceIndexPath.row] retain]; // 2.把起始位置的对象从数据源移除 [self.array removeObjectAtIndex:sourceIndexPath.row]; // 3.把数据插入到数组中 [self.array insertObject:str atIndex:destinationIndexPath.row]; [str release];}
0 0
- 可编辑的TableView
- tableView的编辑模式
- tableView的编辑
- tableview的编辑
- tableView的编辑
- 34.tableView的编辑
- tableView的编辑
- TableView的编辑
- tableView的编辑和移动
- TableView编辑
- TableView编辑
- JAVAFX的TableView的单元格可编辑
- CYC- tableView的删除编辑移动
- 编辑删除收藏在tableView的内容
- CommonTableCollectView使用例子:tableView的编辑模式
- 自定义tableView编辑样式的图标
- ios TableView编辑状态多选框的修改
- TableView 编辑时,底部线的处理
- 最好的10个移动 Web 应用程序开发框架
- Java中的equals和==异同,你知道多少?
- React Native 简介:用 JavaScript 搭建 iOS 应用 (1)
- ImageLoader框架使用步骤
- hdoj1325Is It A Tree?
- tableView的编辑
- 【HDU5371】Hotaru's problem(Manacher + set)
- Singapore National Day (SG50 Golden Jubilee)
- 如何使用1M的内存排序100万个8位数
- ORM进阶:Hibernate的优劣对比
- 开始使用 Spring Data JPA
- 数据结构实验之链表六:有序链表的建立
- 2.3 寻找"水贴王"
- 新手学习C++笔记7:结构体、联合体的区别与联系