iOS UITableView(十三) tableView经常用的代理总结和滑动删除
来源:互联网 发布:淘宝贷款逾期多久抓人 编辑:程序博客网 时间:2024/06/05 17:45
#pragma mark TableView Delegate//对编辑的状态下提交的事件响应-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"commond eidting style "); if (editingStyle == UITableViewCellEditingStyleDelete) { [dataArray removeObjectAtIndex:indexPath.row]; // Delete the row from the data source. [tableview deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; } else if (editingStyle == UITableViewCellEditingStyleInsert) { // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. } }//响应选中事件-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"did selectrow");}//行将显示的时候调用-(void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"will display cell"); }//点击了附加图标时执行-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath{ NSLog(@"accessoryButtonTappedForRowWithIndexPath");}//开始移动row时执行-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath*)destinationIndexPath{ NSLog(@"moveRowAtIndexPath");}//开发可以编辑时执行-(void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"willBeginEditingRowAtIndexPath");}//选中之前执行-(NSIndexPath*)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"willSelectRowAtIndexPath"); return indexPath;}//将取消选中时执行-(NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath{ NSLog(@"willDeselectRowAtIndexPath"); return indexPath;}//移动row时执行-(NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath *)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath{ NSLog(@"targetIndexPathForMoveFromRowAtIndexPath"); //用于限制只在当前section下面才可以移动 if(sourceIndexPath.section != proposedDestinationIndexPath.section){ return sourceIndexPath; } return proposedDestinationIndexPath;}//删除按钮的名字-(NSString*)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ return @"删除按钮的名字";}//让表格可以修改,滑动可以修改-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}//让行可以移动-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}//滑动代理-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ // NSLog(@"手指滑动了"); return UITableViewCellEditingStyleDelete;}//返回组数#pragma mark TableView DataSource-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{ return 1;}//返回每组的数量-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ return [dataArray count];}
<pre name="code" class="objc">
//滑动删除
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath //当在Cell上滑动时会调用此函数{ if(temp == 1 || temp == 2) return UITableViewCellEditingStyleDelete; //返回此值时,Cell会做出响应显示Delete按键,点击Delete后会调用下面的函数,别给传递UITableViewCellEditingStyleDelete参数 else return UITableViewCellEditingStyleNone; //返回此值时,Cell上不会出现Delete按键,即Cell不做任何响应} - (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath //对选中的Cell根据editingStyle进行操作{ if (editingStyle == UITableViewCellEditingStyleDelete) { if (temp == 1) //将单元格从数据库1中删除 { [[CommonDatainstance] delEntity:[[[CommonDatainstance] gainSelectResult] objectAtIndexPath:indexPath]]; [[CommonDatainstance] saveDB]; [[CommonDatainstance] refreshResult:[[CommonDatainstance] gainSelectResult]]; NSArray *array = [[CommonDatainstance] gainSelectResult].fetchedObjects; array = [[self changeArrayForm:array] copy]; self.listData = array; [myTableView reloadData]; } else if (temp == 2) ////将单元格从数据库2中删除 { [[CommonDatainstance] delEntity:[[[CommonDatainstance] gainRecentResult] objectAtIndexPath:indexPath]]; [[CommonDatainstance] saveDB]; [[CommonDatainstance] refreshResult:[[CommonDatainstance] gainRecentResult]]; NSArray *array = [[CommonDatainstance] gainRecentResult].fetchedObjects; array = [[self changeArrayForm:array] copy]; self.listData = array; [myTableView reloadData]; } }}
0 0
- iOS UITableView(十三) tableView经常用的代理总结和滑动删除
- iOS tableview 滑动删除
- iOS tableview 滑动删除
- [IOS]UITableView实现Cell的滑动删除
- iOS之 UITableView 的数据源方法和代理方法总结
- tableView的滑动删除
- tableview的滑动删除
- IOS 构造和使用TableView(基于storyboard) (四)启用Table Viewcell的滑动删除
- iOS TableView经常用得到
- iOS---tableView的代理
- UITableView的多选删除和滑动删除并存
- iOS 使用cell的删除功能,实现tableview的代理
- iphone的tableview滑动删除
- UITableView滑动删除的实现
- iOS TableView横向滑动删除记录
- IOS TableView 左滑动删除Cell方法
- [绍棠] iOS UITableView 的坑:isDragging 属性无效, tableView是拖拽还是自由滑动区分
- ios UITableView的移动、添加和删除
- mysql 实现 oracle 中 rorw_number() over () 函数
- Erlang 学习(一) 环境搭建和Erlang HelloWorld
- Java使用“==”所遇到的坑
- Myeclipse中快捷键大全
- 【React Native开发】React Native应用设备运行(Running)以及调试(Debugging)(3)
- iOS UITableView(十三) tableView经常用的代理总结和滑动删除
- Ubuntu开启WiFi热点(安卓手机可识别)
- 【原创】关于weblogic的classpath、weblogic.xml和JASS设置
- 安卓APK文件结构解析 怎样去除内置广告 及修改图标和文字
- 怎么招聘程序员
- 数据包最大帧字节和最小帧字节
- 思路转换的失败
- ArcGIS10中使用Simple工具箱
- unity对于网址编码和解码EscapeURL和UnEscapeURL