iOS原生态删除、置顶某行cell

来源:互联网 发布:javascript用什么打开 编辑:程序博客网 时间:2024/06/01 17:51

- (NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath

{

    UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructivetitle:@"删除"handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {

        [self.deleteSourceremoveObjectAtIndex:indexPath.row];//根据某行删除某个cell

        [self.tableViewdeleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic]; 

    }];

        UITableViewRowAction *topRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefaulttitle:@"置顶"handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {

        [self.deleteSourceexchangeObjectAtIndex:indexPath.rowwithObjectAtIndex:0];//改变某个cell所在的位置

        NSIndexPath *firstIndexPath = [NSIndexPathindexPathForRow:0inSection:indexPath.section];//将选中的cell 放至第一位

        [tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath];

    }];

    topRowAction.backgroundColor = [UIColorblueColor];

    UITableViewRowAction *moreRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormaltitle:@"更多"handler:^(UITableViewRowAction *_Nonnull action, NSIndexPath *_Nonnull indexPath) {

        [self.tableViewreloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle];

    }];

    return@[deleteRowAction,topRowAction,moreRowAction];

}

0 0
原创粉丝点击