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

    xiaoxiao2025-11-12  4

    - (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];

    }

    转载请注明原文地址: https://ju.6miu.com/read-1304097.html
    最新回复(0)