向左或向右滑动在任何地方一个UITableViewCell删除的单元格没有删除按钮?
2014-07-25 16:10
393 查看
1. 我还没有试过这,但我给它一个镜头。首先,创建一个自定义的UITableViewCell,并让它有2个属性,您一提到的tableView这是英寸 一个indexPath来查找的tableView细胞(注意,这需要更新您删除单元格的所有单元格,其中这改变)在你的
确保手势只接收水平挥笔。
在你的
2. 发布者@MadhavanRP该解决方案的工作原理,但它比它需要。你可以采取一个更简单的方法,并创建一个手势识别来处理发生在表中的所有挥笔,然后拿到刷卡的位置,以确定哪些单元格刷卡。 要设置手势识别:
收回
注意:你的VC必须在手势识别的委托。
3.
这些在UITableViewCellEditingStyle是UITableViewCellEditingStyleDelete,然后做某事抹去你的手机用
仅此而已。
4. 对于u必须添加此项目中的代码。
cellForRowAtIndexPath:,在那里你创建自定义单元格,设置这些属性。还添加了UISwipeGestureRecognizer到细胞
cell.tableView=tableView; cell.indexPath=indexPath; UISwipeGestureRecognizer *swipeGestureRecognizer=[[UISwipeGestureRecognizer alloc] initWithTarget:self action:@"deleteCell:"]; [cell addGestureRecognizer:swipeGestureRecognizer]; [swipeGestureRecognizer release];
确保手势只接收水平挥笔。
-(BOOL) gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if([[gestureRecognizer view] isKindOfClass:[UITableViewCell class]]&& ((UISwipeGestureRecognizer*)gestureRecognizer.direction==UISwipeGestureRecognizerDirectionLeft ||(UISwipeGestureRecognizer*)gestureRecognizer.direction==UISwipeGestureRecognizerDirectionRight)) return YES; }
在你的
deleteCell:
-(void) deleteCell:(UIGestureRecognizer*)gestureRec { UIGestureRecognizer *swipeGestureRecognizer=(UISwipeGestureRecognizer*)gestureRec; CustomCell *cell=[swipeGestureRecognizer view]; UITableView *tableView=cell.tableView; NSIndexPath *indexPath=cell.indexPath; //you can now use these two to perform delete operation }
2. 发布者@MadhavanRP该解决方案的工作原理,但它比它需要。你可以采取一个更简单的方法,并创建一个手势识别来处理发生在表中的所有挥笔,然后拿到刷卡的位置,以确定哪些单元格刷卡。 要设置手势识别:
- (void)setUpLeftSwipe { UISwipeGestureRecognizer *recognizer; recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeLeft:)]; [recognizer setDirection:UISwipeGestureRecognizerDirectionLeft]; [self.tableView addGestureRecognizer:recognizer]; recognizer.delegate = self; }
收回
viewDidLoad办理刷卡:
- (void)swipeLeft:(UISwipeGestureRecognizer *)gestureRecognizer { CGPoint location = [gestureRecognizer locationInView:self.tableView]; NSIndexPath *indexPath = [self.tableView indexPathForRowAtPoint:location]; ... do something with cell now that i have the indexpath, maybe save the world? ... }
注意:你的VC必须在手势识别的委托。
3.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath; - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;
这些在UITableViewCellEditingStyle是UITableViewCellEditingStyleDelete,然后做某事抹去你的手机用
- (void)deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation;
仅此而已。
4. 对于u必须添加此项目中的代码。
// Override to support conditional editing of the table view. - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { // Return YES if you want the specified item to be editable. return YES; } // Override to support editing the table view. - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { if (editingStyle == UITableViewCellEditingStyleDelete) { //add code here for when you hit delete } }
相关文章推荐
- tableView中当我们向右滑动不出现删除按钮(实现了代理方法)的原因
- iOS开发给UITableView的单元格做一个类似于QQ和微信的侧滑露出删除按钮的思路
- 修改UITableViewCell滑动删除按钮标题
- UITableViewCell左滑动删除 和cell上按钮的点击事件
- 通过一个按钮删除我在ListCtrl中选的一项
- 在C#中为DATAGRID控件增加一个删除按钮的一种方法
- DataGrid点击删除按钮弹出确认对话框一个好办法
- Ajax没有出来之时,我曾写的一个按钮确认提示
- DataGrid点击删除按钮弹出确认对话框一个好办法
- 在一个CommandField中为删除按钮设置OnClientClick属性
- 在删除数据库记录前弹出一个对话框,和确认按钮和取消按钮
- DataGrid点击删除按钮弹出确认对话框一个好办法
- wcf指定要序列化多个请求正文参数,但没有任何包装元素。如果没有包装元素,至多可序列化一个正文参数。请删除多余的正文参数,或将 WebGetAttribute/WebInvokeAttribute 的
- 一个多选与删除按钮联动的js
- (转)问题:假设一个没有头指针的单链表。一个指针指向此单链表中间的一个节点(既不是第一个,也不是最后一个节点),请将该节点从单链表中删除。
- hdu 3551 Hard Problem 一般图最大匹配+给出一个无向图,存在重边,没有自环。问能否删除一些边,使得每个顶点的度数为指定度数
- 通过单击按钮产生一个新的没有任务栏的窗体
- DataGrid点击删除按钮弹出确认对话框一个好办法
- DataGrid点击删除按钮弹出确认对话框一个好办法
- DataGrid中全选删除按钮,如果没选,先提示没有选择,再弹出确定删除对话框的例子