ios - UIKit 中的 Xcode 文档选择器委托
问题描述
为什么我不能将委托设置为自我?我在 viewcontroller.swift 文件中运行下面的代码,但我想在 Render.swift 文件中调用它。我有一个运行相机视图的金属场景,想打开它前面的文件选择器,但这似乎不是很简单。
@IBAction func importFiles(_ sender: Any) {
let documentPicker = UIDocumentPickerViewController(documentTypes: [kUTTypePlainText as String], in: .import)
documentPicker.delegate = self
documentPicker.allowsMultipleSelection = false
present(documentPicker, animated: true, completion: nil)
}
它说无法将“ViewController”类型的值分配给“UIDocumentPickerDelegate”类型
在我的 Renders.swift 文件中,我有一个绑定到按钮的函数,该按钮调用以下内容:
//open dialog for picker...
let myVC: ViewController = ViewController()
myVC.importFiles()
我对这一切都很陌生。
解决方案
为什么我不能将委托设置为自我?
因为委托需要是 UIDocumentPickerDelegate,而不是self
UIDocumentPickerDelegate 。您需要声明它是:
class ViewController : UIViewController, UIDocumentPickerDelegate {
这可能会引发其他问题(我希望它会),但至少你会超越现在的状态。
推荐阅读
- android - 为各种 Android 操作系统版本设置推送通知图标
- python - 在日期时间中每 10 分钟绘制一次
- amazon-web-services - 具有特定角色的环境变量的 AWS CLI 登录
- python - 从像素坐标周围的图像中提取 5x5 补丁
- sql - 如何重写 COUNT DISTINCT?
- java - 如果后面有另一个窗口,则透明 JavaFX 阶段捕获滚动事件
- sql - 多于一行的 SQL 约束
- node.js - 如何在 Typescript 输出中使用 node --experimental-modules
- fonts - 如何将字体添加到 abcpdf 7
- reactjs - 为什么我在 react-intl V3.2.2 中出现解析错误?