tableViewCell 多选,索引,汉字排序,左滑操作

来源:互联网 发布:温州网络学堂登录 编辑:程序博客网 时间:2024/06/06 02:38

1.多选的实现,直接设置tableview的两个属性就可以了。

_tableview.allowsMultipleSelectionDuringEditing =YES;

 [_tableviewsetEditing:YESanimated:YES];//之所以这样写,没有直接用点语法是因为这样有动画效果。

系统默认选中的时候颜色是蓝色的,修改颜色的话,直接用_tableView.tintColor属性就可以了。

2.左滑操作,是ios8才支持的。直接写在代理方法里面,返回一个UITableViewRowAction的数组。(这个用第三方库也能实现,一个牛逼的左右滑动的第三方https://github.com/MortimerGoro/MGSwipeTableCell)

- (nullableNSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{    UITableViewRowAction *deleteRoWAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructivetitle:@"工单"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {        CreatNew_ViewController *creatVC = [[CreatNew_ViewControlleralloc]init];        creatVC.detailDataArray =_dataArray;        creatVC.cellPage = indexPath.row;        [self.navigationControllerpushViewController:creatVCanimated:YES];    }];//此处是iOS8.0以后苹果最新推出的api,UITableViewRowAction,Style是划出的标签颜色等状态的定义,这里也可自行定义    UITableViewRowAction *editRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"分配"handler:^(UITableViewRowAction *action,NSIndexPath *indexPath) {        _isAlone =YES;        if (!isopen) {            buttomView.hidden =NO;            [UIViewanimateWithDuration:0.5animations:^{                buttomView.frame =CGRectMake(0,kMainScreenH-44-40-200,kMainScreenW,240);            }];        }else        {            [UIViewanimateWithDuration:0.5animations:^{                buttomView.frame =CGRectMake(0,kMainScreenH-44,kMainScreenW,240);            } completion:^(BOOL finished) {                buttomView.hidden =YES;            }];        }        isopen = !isopen;    }];    editRowAction.backgroundColor = [UIColorcolorWithRed:0green:124/255.0blue:223/255.0alpha:1];//可以定义RowAction的颜色    return@[deleteRoWAction, editRowAction];//最后返回这俩个RowAction的数组}


3.索引和汉字排序用的人家写好的类,系统自带的类也可以实现。

demo百度云:链接: http://pan.baidu.com/s/1gf0MQp9 密码: 2u34

0 0
原创粉丝点击