除了如何处理UIDocuments之外,所有关于拖放的事情都很清楚。
这是我的(不起作用)实现.
拖曳:
func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
let doc = DataManager.shared.storage[indexPath.row] // the UIDocument to drag
let itemProv = NSItemProvider()
itemProv.registerFileRepresentation(forTypeIdentifier: "com.mybundle.myapp.myextension",
fileOptions: [.openInPlace],
visibility: .all) { completionHandler in
completionHandler(doc.fileURL, true, nil)
return nil
}
// DragItem
let item = UIDragItem(itemProvider: itemProv)
return [item]
}
滴滴:
func tableView(_ tableView: UITableView, performDropWith coordinator: UITableViewDropCoordinator) {
for item in coordinator.session.items {
item.itemProvider.loadFileRepresentation(forTypeIdentifier: "com.mybundle.myapp.myextension", completionHandler: { (url, error) in
if let docUrlOk = url {
debugPrint(urlOk.absoluteString)
DataManager.shared.load(docUrlOk)
}
})
}
}
以及更新方法:
func tableView(_ tableView: UITableView, dropSessionDidUpdate session: UIDropSession, withDestinationIndexPath destinationIndexPath: IndexPath?) -> UITableViewDropProposal {
if tableView.hasActiveDrag {
if session.items.count > 1 {
return UITableViewDropProposal(operation: .cancel)
} else {
return UITableViewDropProposal(operation: .move, intent: .insertAtDestinationIndexPath)
}
} else {
return UITableViewDropProposal(operation: .copy, intent: .insertAtDestinationIndexPath)
}
}
非常感谢
发布于 2018-03-22 17:46:59
经过与苹果工程师的多次交谈,我找到了一个“半”解决方案。问题中发布的代码是正确的,但是要将专有文件从应用程序拖到文件应用程序中,必须在目标->信息->导出的UTIs字段中插入以下值
但是如果您将您的专有文件从Files拖回到您的应用程序中,UIKit中有一个缺陷,使它无法正常工作。工程师让我等iOS 11.3或iOS 12,我们看看
发布于 2017-09-13 12:36:17
如果在iPhone中运行代码,则需要设置dragItem.enable = YES。
https://stackoverflow.com/questions/45939582
复制相似问题