You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何隐藏QLPreviewController中Done按钮菜单的「Save to Files」选项?

解决QLPreviewController编辑PDF后隐藏「Save to Files」选项的问题

要隐藏编辑PDF后点击「Done」弹出的「Save to Files」选项,你可以通过实现QLPreviewControllerDelegate的特定方法拦截系统的保存提示,具体操作如下:

  • 给QLPreviewController设置代理,并确保当前类遵守QLPreviewControllerDelegate协议
  • 实现previewController(_:shouldSaveEditedCopyOf:at:)方法并返回false,告知系统无需弹出保存选项(因为你已自行完成应用内自动保存)

修改后的完整代码示例:

// 确保当前类遵守对应协议
class YourViewController: UIViewController, QLPreviewControllerDataSource, QLPreviewControllerDelegate {

    func previewController(_ controller: QLPreviewController, previewItemAt index: Int) -> QLPreviewItem {
        return getFileURLFromFileModel()! as QLPreviewItem
    }

    func displayPDFForAnnotation(){
        let previewController = QLPreviewController()
        previewController.dataSource = self
        // 设置代理
        previewController.delegate = self
        self.present(previewController, animated: true)
    }

    // 实现代理方法,拦截保存提示
    func previewController(_ controller: QLPreviewController, shouldSaveEditedCopyOf previewItem: QLPreviewItem, at modifiedContentsURL: URL) -> Bool {
        // 若需补充自定义保存逻辑可在此添加
        // 因已实现应用内自动保存,直接返回false隐藏「Save to Files」选项
        return false
    }
}

说明

该方法支持iOS 13及以上版本,它允许你控制编辑后的PDF是否触发系统默认保存流程。返回false后,系统会跳过「Save to Files」弹窗,你可在此方法内确认自身自动保存逻辑的执行状态。

内容的提问来源于stack exchange,提问作者Ranadhir

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.30 13:59:56