您的位置:首页 > 产品设计 > UI/UE

UITableView实现Cell的滑动删除

2015-06-29 12:00 411 查看
转载请标明出处:/article/7738602.html

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(@"我要删除这篇帖子,请执行命令,谢谢");

}
}


已实现的效果图如下:



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: