我正在关注UIDocumentMenuViewController的Apple文档,以下是我的代码。 importMenu.delegate = self不起作用,Xcode显示:无法分配类型的值' ViewController'键入' UIDocumentMenuDelegate?' 。请帮忙。谢谢!
import UIKit
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
let importMenu = UIDocumentMenuViewController(documentTypes: ["public.text", "public.data"], inMode: .Import)
importMenu.delegate = self
self.presentViewController(importMenu, animated: true, completion: nil)
}
}
答案 0 :(得分:1)
根据UIDocumentMenuDelegate Protocol Reference,您的ViewController
必须符合UIDocumentMenuDelegate
并且必须实施documentMenu:didPickDocumentPicker:
extension ViewController: UIDocumentMenuDelegate {
func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
// do stuffs here
}
}
答案 1 :(得分:0)
您的委托类应该从视图控制器中的UIDocumentMenuViewDelegate
扩展
import UIKit
class ViewController: UIViewController, UIDocumentMenuViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let importMenu = UIDocumentMenuViewController(documentTypes: ["public.text", "public.data"], inMode: .Import)
importMenu.delegate = self
self.presentViewController(importMenu, animated: true, completion: nil)
}
}