首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >iOS 11拖放UIDocument

iOS 11拖放UIDocument
EN

Stack Overflow用户
提问于 2017-08-29 12:47:09
回答 2查看 767关注 0票数 3

除了如何处理UIDocuments之外,所有关于拖放的事情都很清楚。

这是我的(不起作用)实现.

拖曳:

代码语言:javascript
运行
复制
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]
}

滴滴:

代码语言:javascript
运行
复制
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)
            }
        })
    }
}

以及更新方法:

代码语言:javascript
运行
复制
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)
    }
}

非常感谢

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2018-03-22 17:46:59

经过与苹果工程师的多次交谈,我找到了一个“半”解决方案。问题中发布的代码是正确的,但是要将专有文件从应用程序拖到文件应用程序中,必须在目标->信息->导出的UTIs字段中插入以下值

但是如果您将您的专有文件从Files拖回到您的应用程序中,UIKit中有一个缺陷,使它无法正常工作。工程师让我等iOS 11.3或iOS 12,我们看看

票数 3
EN

Stack Overflow用户

发布于 2017-09-13 12:36:17

如果在iPhone中运行代码,则需要设置dragItem.enable = YES

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45939582

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档