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

UITTableView滑动删除

2016-06-28 20:07 405 查看
代码:

#pragma mark-tableView的删除代理方法
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return
YES;
}
//返回编辑类型
- (UITableViewCellEditingStyle )tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath
*)indexPath
{
    return
UITableViewCellEditingStyleDelete;
}

//编辑操作
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle ==
UITableViewCellEditingStyleDelete)
    {
        //删除行
        //1.删除数据源
        //2.界面上删除cell
        teleModel *model =
self.datasources[indexPath.row];
        
        //数据删除
        [[DatabaseManager
sharedManager]deleModel:model];
        
        [self.datasources
removeObjectAtIndex:indexPath.row];
        
        //直接刷新表格,没有动画
        [tableView reloadData];
    }
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: