0

我正在关注 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)

   }
}
4

2 回答 2

1

根据UIDocumentMenuDelegate Protocol Reference,您ViewController必须符合UIDocumentMenuDelegate并且必须实现documentMenu:didPickDocumentPicker:

extension ViewController: UIDocumentMenuDelegate {
    func documentMenu(documentMenu: UIDocumentMenuViewController, didPickDocumentPicker documentPicker: UIDocumentPickerViewController) {
        // do stuffs here
    }
}
于 2016-05-05T13:54:47.920 回答
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)

   }
}
于 2016-05-05T13:52:07.487 回答