1. 程式人生 > >ios tableview cell 側滑刪除

ios tableview cell 側滑刪除

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

{

returnTRUE;

}

- (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 = [NSData dataWithContentsOfFile:path];//讀取檔案

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

    [array1 removeObjectAtIndex:row];

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

NSData* data2=[NSKeyedArchiverarchivedDataWithRootObject:array];

    [data2 writeToFile:path atomically:YES];

    _datalist

=array1;

    [_tablereloadData];

}

在上面的函式裡面寫資料更新的操作。。。。。