删除和添加tableView的cell
2016-10-12 本文已影响41人
Dove_Q
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[tableView deselectRowAtIndexPath:indexPath animated:NO];
//左边会出现那个减号
tableView.editing = YES;
[_tag insertObject:@"*项目1" atIndex:indexPath.row + 1];
NSIndexPath *addIndexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:0];
//在tableView中添加一行cell
[tableView insertRowsAtIndexPaths:@[addIndexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
//在数组中删除一个
[_tag removeObjectAtIndex:indexPath.row];
//在tableView中删除一行
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
NSLog(@"---->%ld", indexPath.row);
}