您的位置:首页 > 其它

tableView左滑删除功能

2015-06-15 12:03 281 查看
实现三个代理方法即可



-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
return @"删除";
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{   if (!indexPath.section) return UITableViewCellEditingStyleNone; // 第一组家和公司不提供左滑删除功能
return UITableViewCellEditingStyleDelete;
}
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {

[self.commonPlaceArray removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:@[indexPath]
withRowAnimation:UITableViewRowAnimationAutomatic];
[self.tableView reloadData];
}
}


上面说漏了一点,就是有个代理方法是开启允许进入编辑状态的,这样才可以进行左滑或者添加的其他操作,注意当你左滑后,没有把这个cell滑回去,这时候如果你在返回上一个页面可能会崩溃,这个时候你需要在viewWillDisappear方法中将这个编辑状态置为NO,好的,现在终于操作流畅了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: