美文网首页
删除和添加tableView的cell

删除和添加tableView的cell

作者: Dove_Q | 来源:发表于2016-10-12 18:54 被阅读41次
- (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);
}

相关文章

网友评论

      本文标题:删除和添加tableView的cell

      本文链接:https://www.haomeiwen.com/subject/zbiiyttx.html