UITTableView滑动删除

来源:互联网 发布:mac语音播报怎么关闭 编辑:程序博客网 时间:2024/06/03 23:44

代码:

#pragma mark-tableView的删除代理方法

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

{

    returnYES;

}

//返回编辑类型

- (UITableViewCellEditingStyle )tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

{

    returnUITableViewCellEditingStyleDelete;

}


//编辑操作

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

{

    if (editingStyle ==UITableViewCellEditingStyleDelete)

    {

        //删除行

        //1.删除数据源

        //2.界面上删除cell

        teleModel *model =self.datasources[indexPath.row];

        

        //数据删除

        [[DatabaseManagersharedManager]deleModel:model];

        

        [self.datasourcesremoveObjectAtIndex:indexPath.row];

        

        //直接刷新表格,没有动画

        [tableView reloadData];

    }

}


0 0
原创粉丝点击