ios tableview cell 侧滑删除

来源:互联网 发布:淘宝店铺头像在哪里换 编辑:程序博客网 时间:2024/05/01 20:51

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

{

    return TRUE;

}


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

{

    returnUITableViewCellEditingStyleDelete;

}


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

    NSInteger row=[indexPath row];

    NSString *path = [NSStringstringWithFormat:@"%@/Documents/save.dat",NSHomeDirectory()];

    NSData *data1 = [NSDatadataWithContentsOfFile:path];//读取文件

    NSMutableArray* array1 = [NSKeyedUnarchiverunarchiveObjectWithData:data1];//反序列化

    [array1 removeObjectAtIndex:row];

    NSMutableArray* array=[[NSMutableArrayalloc]initWithArray:array1];

    NSData* data2=[NSKeyedArchiverarchivedDataWithRootObject:array];

    [data2 writeToFile:pathatomically:YES];

    _datalist=array1;

    [_tablereloadData];



    

}

在上面的函数里面写数据更新的操作。。。。。

0 0
原创粉丝点击