UIDocumentInteractionController presentOpenInMenuFromRect

UIDocumentInteractionController presentOpenInMenuFromRect

我有从 UIAlertController 中调用的代码:

func createSomeFile() {

    var output = (some NSData to output to file)


    let fileName = NSTemporaryDirectory().stringByAppendingPathComponent("filename.ext")
    let url: NSURL! = NSURL(fileURLWithPath: fileName)

    var dataToWrite = output.dataUsingEncoding(NSUTF8StringEncoding)
    dataToWrite?.writeToFile(url.absoluteString!, atomically: true)

    documentController = UIDocumentInteractionController(URL: url)
    documentController.UTI = "com.someUTI"
    documentController.delegate = self

    documentController.presentOpenInMenuFromRect(CGRectZero, inView: self, animated: true)
}

最后一行在Xcode中抛出错误:"Cannot invoke 'presentOpenInMenuFromRect' with an argument list of type..."

documentController 声明为 class 变量 var documentController = UIDocumentInteractionController()

请帮我解决这个问题。

你不能将 self 分配给一个应该是 UIView 的参数(除非 selfUIView 的子类,但显然它不是)

所以试试这个:

documentController.presentOpenInMenuFromRect(CGRectZero, inView: self.view, animated: true)