[英]Trying to export to csv but how do i implement from delegate?
[new to swift] I testing this function to export some simple file [new to swift]我测试这个函数来导出一些简单的文件
@IBAction func exportFile(delegate: UIDocumentInteractionControllerDelegate) {
print("export csv")
let fileName = tmpDir.stringByAppendingPathComponent("myFile.csv")
let url: NSURL! = NSURL(fileURLWithPath: fileName)
if url != nil {
let docController = UIDocumentInteractionController(URL: url)
docController.UTI = "public.comma-separated-values-text"
docController.delegate = delegate
docController.presentPreviewAnimated(true)
}
}
// Return the view controller from which the UIDocumentInteractionController will present itself.
func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController)-> UIViewController {
return self
}
But when i clicked the export button i am getting the message 但是当我点击导出按钮时,我收到了消息
UIDocumentInteractionController delegate must implement documentInteractionControllerViewControllerForPreview: to allow preview
I thought 我想
class ViewController: UIViewController, UIDocumentInteractionControllerDelegate {
class ViewController:UIViewController,UIDocumentInteractionControllerDelegate {
Would be sufficient? 会足够吗?
I tried Self.documentInteractionControllerViewForPreview(docController) 我试过Self.documentInteractionControllerViewForPreview(docController)
[edit] turned out i had made the following mistake docController.delegate = self//delegate [编辑]原来我犯了以下错误docController.delegate = self //委托
You need to implement following delegate methods. 您需要实现以下委托方法。 Delegates are the callbacks from the service provider to service consumer to be prepared for the action that is about to occur.
代表是从服务提供者到服务使用者的回调,为即将发生的操作做好准备。 On some occasions you must provide details (called data source) in order to utilise the said functionality.
在某些情况下,您必须提供详细信息(称为数据源)才能使用所述功能。
func documentInteractionControllerViewControllerForPreview(controller: UIDocumentInteractionController!) -> UIViewController! {
return self
}
func documentInteractionControllerViewForPreview(controller: UIDocumentInteractionController!) -> UIView! {
return self.view
}
func documentInteractionControllerRectForPreview(controller: UIDocumentInteractionController!) -> CGRect {
return self.view.frame
}
Read through how delegation works . 阅读委托如何运作 。 Also, take a look at your specific case here .
另外,请在此处查看您的具体案例。
For Swift 3.0 对于Swift 3.0
First extend your class 首先扩展你的课程
UIDocumentInteractionControllerDelegate
Then only implement the following method 然后只实现以下方法
func documentInteractionControllerViewControllerForPreview(_ controller: UIDocumentInteractionController) -> UIViewController {
return self
}
Calling the Pdf Viewer 调用Pdf Viewer
func MyViewDocumentsmethod(){
let controladorDoc = UIDocumentInteractionController(url: PdfUrl! as URL)
controladorDoc.delegate = self
controladorDoc.presentPreview(animated: true)
}
This should render the following 这应该呈现以下内容
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.