是否可以对表进行编辑
[self.tableView setEditing:BOOL animated:YES];
BOOL 为YES 可对表中的数据进行如下操作:
移动
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath { return YES; } - (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath { NSUInteger fromRow = [sourceIndexPath row]; NSUInteger toRow = [destinationIndexPath row]; id object = [[listOne objectAtIndex:fromRow] retain]; [listOne removeObjectAtIndex:fromRow]; [listOne insertObject:object atIndex:toRow]; }
删除
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { NSUInteger row = [indexPath row]; [self.listOne removeObjectAtIndex:row]; [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; }
对表进行添加操作以后就表进行更新
[self.tableView reloadData];