是否可以使用iOS 11拖放来重新排序UITableView中的多个项目/单元格?
我知道在使用新代表UITableViewDropDelegate
和UITableViewDragDelegate
代表时可以重新排序单个项目/单元格,但是可以支持处理多个项目/单元格。是否可以使用iOS 11拖放来重新排序UITableView中的多个项目/单元格?
和删除单元格把它放在到位。
然而,当我抢多个单元格,我得到了禁止进入标志和细胞惯于重新排序:
如果从另一个应用程序,它工作正常我多个项目,例如拖多条消息出来的iMessage的:
当只用本地项目重新排序表视图时可以这样做,以便您可以更快地重新排序?
这里是我的代码:
UITableViewDragDelegate
extension DotViewController: UITableViewDragDelegate {
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
return [getDragItem(forIndexPath: indexPath)]
}
func tableView(_ tableView: UITableView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] {
return [getDragItem(forIndexPath: indexPath)]
}
func getDragItem(forIndexPath indexPath: IndexPath) -> UIDragItem {
// gets the item
}
}
UITableViewDropDelegate
extension DotViewController: UITableViewDropDelegate {
func tableView(_ tableView: UITableView, canHandle session: UIDropSession) -> Bool {
return true
}
func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {
// Handles Drop
}
}
viewDidLoad
override func viewDidLoad() {
super.viewDidLoad()
tableView.dataSource = self
tableView.delegate = self
tableView.dragDelegate = self
tableView.dropDelegate = self
tableView.dragInteractionEnabled = true
}
它的PO可以通过您的拖拽代理(例如,通过拖拽代理)提供对所有选定单元格的引用来自行执行多行重新排序。一个section.row的数组)然后实现tableView:performDropWith:withCoordinator来对它们进行重新排序。 (我怀疑你知道这一点)
如果你想通过返回UITableViewDropProposal一滴建议,以支持重排(操作:.move,意图:.insertAtDestinationIndexPath),所以UIKit的使用预iOS版11的tableView:moveRowAt:以函数,那么这只支持单行。
表视图moveRowAt IndexPath到IndexPath。如果你愿意,你可以继续实现这个功能,以支持重新排序,使用Drag和 拖放。因为表视图实际上会调用此函数而不是 通过与协调器执行拖放操作进行调用,如果您已返回那个幻灯片提议并且实际上正在对一行进行重新排序。
来源:https://developer.apple.com/videos/play/wwdc2017/223/?time=1836
你能否澄清如何多行重新排序可以实现?你是在实现低级的拖拽委托方法而不是'UITableViewDragDelegate'吗? –