swift - 使我的 ViewController 符合 NSDraggingDestination 协议
问题描述
有人可以向我解释以下代码有什么问题吗?我正在尝试使我的 ViewController 符合 NSDraggingDestination 协议,但在该行出现错误:
self.registerForDraggedTypes(supportedTypes)
告诉我“'ViewController 类型的值没有成员'registerForDraggedTypes'
这是 ViewController 代码:
import Cocoa
import Foundation
class ViewController: NSViewController, NSDraggingDestination {
@IBOutlet var statusScrollView: NSScrollView!
let supportedTypes: [NSPasteboard.PasteboardType] = [.tiff, .fileURL]
override func viewDidLoad() {
super.viewDidLoad()
self.registerForDraggedTypes(supportedTypes)
}
override var representedObject: Any? {
didSet {
// Update the view, if already loaded.
}
}
@IBAction func checkButton(_ sender: NSButtonCell) {
print("check button pressed.")
}
}
任何帮助深表感谢。谢谢!
解决方案
请检查 NSViewController 是否具有 registerForDraggedTypes(_ types:[NSPasteboard.PasteboardType]) 函数。
我认为您的 ViewController 和 NSViewController 都没有函数调用 registerForDraggedTypes()
推荐阅读
- android - CMake 输出工件作为 gradle 依赖项
- stm32 - stm32h7微控制器的sdram读/写问题
- javascript - 循环访问javascript对象的问题
- java - Android appcompat-v7:28.0.0-rc01 预览不起作用
- javascript - normal.js:19 未捕获的类型错误:无法将属性“innerHTML”设置为 null
- firebase - 颤振:firebase消息导航器不起作用
- c++ - OpenGL 纹理未显示(我不使用着色器)
- c# - 使用实体框架从单个控件将数据输入多个表的过程
- docker - 如何将 docker 层拆分为较小的文件(上传时)?
- javascript - InnerHtml 中的 Angular 6 自定义元素不断重新加载