转载请标明出处:http://blog.csdn.net/android_ls/article/details/46680557
UITableViewCell的滑动删除实现代码如下:
#pragma mark 当用户手指在Cell上滑动时会调用此函数
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.section){
// 返回UITableViewCellEditingStyleDelete时,Cell会做出响应显示Delete按键,
// 点击Delete后会调用函数:
// - (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath)
// 并把UITableViewCellEditingStyleDelete当做参数传递过去
return UITableViewCellEditingStyleDelete;
} else {
// 返回UITableViewCellEditingStyleNone时,Cell上不会出现Delete按键,即Cell不做任何响应。
return UITableViewCellEditingStyleNone;
}
}
#pragma mark 对选中的Cell根据editingStyle进行操作
- (void) tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
MyLog(@"我要删除这篇帖子,请执行命令,谢谢");
}
}
已实现的效果图如下: