table的编辑模式(多选,插入,删除)

来源:互联网 发布:万国数据代管服务器吗 编辑:程序博客网 时间:2024/06/05 19:52
//设置table的任意位置,开启何种编辑模式

-(UITableViewCellEditingStyle)tableVIew:(UITableView *)tableVIew editingStyleForRowAnIndexPath:(NSIndexPath *)indexPath
{
    //单是单,一起就是多选
    return UITableViewCellEditingStyleInsert |           UITableViewCellEditingStyleDelete;
}

-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
    [super setEditing:editing animated:animated];
    UITableView *table = (UITbaleView *)[self.view viewWithTag:6666];
    [table setEditing:editing animated:YES];
}

多选数据的手机工作(把打上勾的行存到removeArr里,把取消打钩的行从removeArr里移除)
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //把要删除的这一行,对应数据源数组self.dataArr里面那个元素存进准备删除的数组
    [self.removeArr addObject:self.dataArr[indexPath.row]];
}

-(void)tableView:(UITableView *)tableView didDeselectRowAnIndexPath:(NSIndexPath *)indexPath
{
    TableModel *model = seld.dataArr[indexPath.row];
    //判断删除数组中是否有现在被取消选中这一行的这个元素
    if([self.removeArr containsObject:model])
    {
        //如果这行对应数据源中的元素已经在之前的操作中存进了删除数组,那么把他从删除数组中移除
    [self.removeArr removeObject:model];
    }
}



!!!!!
-(void)btnDown
{
改变数据源,从数据源数组中,把属于删除数组的那些元素删掉
从第一个数组中把属于第二个数组的元素删掉
[self.dataArr removeObjectsInArray:self.removeArr];
UITableView *table = (UITableView *)[self.view viewWithTag:6666];
[table reloadData];
}

0 0
原创粉丝点击