UITableView将单元格拖放到最后一个单元格下方的列表底部

时间:2020-10-07 02:01:09

标签: ios swift uitableview drag-and-drop

在此特定问题上我还没有找到任何东西。我希望能够将UITableViewCell拖放到表格的底部,最后一项的下方。很明显,我可以将一个单元格拖到最后一个单元格的位置上,但是一旦将其拖到最后一个单元格的区域下方,拖动的类型就会取消,并且该单元格会回到其原始位置。

如何将一个项目拖到最后一个项目的下方

Dragging to bottom snaps item back to original position

我没有在桌上做任何异常的事情。这似乎是标准行为。

    func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
        if renamingIndexPath != nil { return [] }
        
        return [UIDragItem(itemProvider: NSItemProvider())]
    }
    
    func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
        if session.localDragSession != nil { // Drag originated from the same app.
            return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
        }
        return UITableViewDropProposal(operation: .cancel, intent: .unspecified)
    }
    
    func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {
        let destinationIndexPath: IndexPath

        if let indexPath = coordinator.destinationIndexPath {
            destinationIndexPath = indexPath
        } else {
            let section = tableView.numberOfSections - 1
            let row = tableView.numberOfRows(inSection: section)
            destinationIndexPath = IndexPath(row: row, section: section)
        }
    }
    
    // Keeps the items inside the same app
    func tableView(_ tableView: UITableView, dragSessionIsRestrictedToDraggingApplication session: UIDragSession) -> Bool {
        return true
    }

0 个答案:

没有答案