2010-12-16 13 views
0

是否有任何委托方法称为“瞬间单击表格单元格中的一个滑动操作并删除按钮从右侧进入?在单元格上滑动指纹的代理方法

我想跟踪滑动并在那里做一些动作。

此外,当您点击单元格中的“删除”按钮时会调用哪个委托方法。

alt text

回答

6

UITableViewDelegate的方法tableView:editingStyleForRowAtIndexPath:将被称为行输入 “编辑” 模式之前。这在您滑动单元格时以及在表视图接收到setEditing:animated消息时调用。如果你有一个编辑按钮将表格视图置于编辑模式,你需要知道每个可见单元格都会被调用。当您点击删除按钮tableView:commitEditingStyle:forRowAtIndexPath:被称为

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView 
      editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath { 
    if (tableView.editing) { 
     return UITableViewCellEditingStyleDelete; 
    } 
    else { 
     // do your thing 
     return UITableViewCellEditingStyleDelete; 
    } 
} 

所以,你可以这样做。

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 

    if (editingStyle == UITableViewCellEditingStyleDelete) { 
     // repsond to delete 
    }  
} 

如果你想改变的删除按钮的文字可以使用tableView:titleForDeleteConfirmationButtonForRowAtIndexPath:

如果对方不想显示的删除按钮,但做其他的事情你应该看看UISwipeGestureRecognizer并处理它你自己。

+0

非常棒的信息。非常感谢先生! – Abhinav 2010-12-16 18:40:07

+0

@Robert不错! +1 :) – TonyMkenu 2012-11-28 07:47:59

相关问题