iOS UITableView2

1 单元格的编辑

本身自带刷新 你用自己的方法刷新的时候要注意

//—————-编辑多选模式—————–
//1.首先在我们的头试图上增加一个button,用于控制tableView是否处于编辑状态
//2.设置哪些单元格可以编辑,哪些单元格不能编辑,默认可编辑
//3.设置每个单元格的编辑模式下的按钮样式(新增和删减),默认删除
//4.在commitEditing方法里增加加减少,要使用_dataLIte,使用reloadData或者增加cell的方法实现
//5.设置可移动
//6.移动的位置调整,先取下来,删除原位置,增加插入新围智

  • (void)editButtonAct:(UIButton *)button{

    button.selected = !button.selected;

    if(button.selected == YES){

    [tableView setEditing:YES animated:YES];
    

    }else{

    [tableView setEditing:NO animated:YES];
    

    }

}

2 单元格移动

首先可以被编辑

  • (BOOL)tableView:(UITableView )tableView canMoveRowAtIndexPath:(NSIndexPath )indexPath{

    return YES;
    }

  • (void)tableView:(UITableView )tableView moveRowAtIndexPath:(NSIndexPath )sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{

    //保存元数据
    NSMutableArray *arrayS = rootArray[sourceIndexPath.section];

    NSString *str = arrayS[sourceIndexPath.row];

    //删除原位置的数据
    [rootArray[sourceIndexPath.section] removeObjectAtIndex:sourceIndexPath.row];

    //插入新位置的数据
    [rootArray[destinationIndexPath.section] insertObject:str atIndex:destinationIndexPath.row];

    //刷新
    [tableView reloadData];

}

3谓词搜索

1.tableView 首先要看有没有谓词搜索

2.做谓词搜索时 首先要设两个根数组 一个新数组不可变 一个旧数组可变

3.数组 filter谓词 要分清对那一个数组做 是对root数组做还是对root数组的数组做 可以先打印出来看一看

reason: ‘Can’t do regex matching on object 就是找错了数组

4.对Root数组的数组做谓词 可以使用for_in循环 这样就不止距现在在只对组做谓词搜索

//============谓词搜索

  • (void)textChange{

    NSString str = [NSString stringWithFormat:@”self like [C] ‘%@*’”,sort.text];

    NSPredicate *predict = [NSPredicate predicateWithFormat:str];

    NSMutableArray *array3 = [[NSMutableArray alloc]initWithCapacity:1];

    for(NSMutableArray *array in root){

    NSArray *array1 = [array filteredArrayUsingPredicate:predict];
    
    if(array1 != NULL){
    
        [array3 addObject:array1];
    }
    

    }

    rootArray = [[NSArray alloc]initWithArray:array3];

    [tableView reloadData];
    }

//设置行高

==去掉没有的组头视图
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{

NSArray *array = rootArray[section];

if(array.count == 0){

    return 0;

}else{

    return 30;
}

}

//快捷搜索
手打一下这个方法 博客不显示返回值
- sectionIndexTitlesForTableView:(UITableView *)tableView{

return@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"];

// @[@”1”,@”2”,@”3”,@”4”,@”5”,@”6”,@”7”,@”8”,@”9”,@”10”,@”11”,@”12”]; 跟前面的组数一直
}

4点击头视图收起section

BOOL isSelect[100];

-(UIView )tableView:(UITableView )tableView viewForHeaderInSection:(NSInteger)section{

UIView *view = [[UIView alloc]init];

UIButton *label = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 375, 30)];

[label setTitle:[NSString stringWithFormat:@"  第%ld组",(long)section] forState:UIControlStateNormal];

label.backgroundColor = [UIColor yellowColor];

[view addSubview:label];

[label setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

view.backgroundColor = [UIColor cyanColor];

[label addTarget:self action:@selector(headerSevtionButtonAct:) forControlEvents:UIControlEventTouchUpInside];

label.tag = 100+section;

return view;

}

  • (void)headerSevtionButtonAct:(UIButton *)button{

    isSelect[button.tag - 100] = ! isSelect[button.tag - 100];

    [tableView reloadData];
    }

  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if(isSelect[section] == NO){

    NSArray *array = rootArray[section];
    
    return array.count;
    

    }else{

    return 0;
    

    }
    }

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值