我想使用拖放委托实现从UICollectionView到UITableViewController的拖动
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
}
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {
}
如何实现此功能?
答案 0 :(得分:1)
快速完成一个测试项目,据我测试,它工作正常。 Trelloesque
秘密是以下两种方法:
func convertPointToIndexPath(point: CGPoint) -> (UITableView, NSIndexPath)? {
if let tableView = [tableView1, tableView2, tableView3].filter({ $0.frame.contains(point) }).first {
let localPoint = scrollView.convertPoint(point, toView: tableView)
let lastRowIndex = focus?.0 === tableView ? tableView.numberOfRowsInSection(0) - 1 : tableView.numberOfRowsInSection(0)
let indexPath = tableView.indexPathForRowAtPoint(localPoint) ?? NSIndexPath(forRow: lastRowIndex, inSection: 0)
return (tableView, indexPath)
}
return nil
}
虽然不完全相同,但我认为它足以让您继续工作。
免责声明:没有时间对其进行测试,因此可能容易出错。