UITableView(二编辑插入)

来源:互联网 发布:巴尔坦星人 知乎 编辑:程序博客网 时间:2024/05/17 07:51
2.插入行
//设置编辑样式-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{           if (indexPath.section == 1) {        return   UITableViewCellEditingStyleDelete; //第二个编辑样式为删除    }    else if (indexPath.section ==2){        return UITableViewCellEditingStyleInsert; //第三个编辑样式为添加    }    return UITableViewCellEditingStyleNone;   }
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{        if (editingStyle == UITableViewCellEditingStyleInsert) {         NSLog(@"%s,%d",__FUNCTION__,__LINE__);        if (2 == indexPath.row) {            //添加新生            NSMutableArray * oneGoupArray = [_allGroupArray objectAtIndex:indexPath.section];            [oneGoupArray addObject:@"云"];                        //实现UI            NSIndexPath * insertIndexPath = [NSIndexPath indexPathForRow:indexPath.row+1 inSection:indexPath.section];            [tableView insertRowsAtIndexPaths:[NSArray arrayWithObjects:insertIndexPath, nil] withRowAnimation:UITableViewRowAnimationRight];        }            }}


0 0
原创粉丝点击