我不确定如何从我保存文件的documentsPath和目标路径获取url
let someText = Nsstring(string: "Test") let documentsPath = NSSearchPathForDirectorIEsInDomains(.documentDirectory,.UserDomainMask,true)[0] as String let destinationPath = documentsPath.stringByAppendingPathComponent("Data.txt") var error:NSError? let written = someText.writetofile(destinationPath,atomically: true,enCoding: NSUTF8StringEnCoding,error: &error) if written{ println("Successfully stored the file at path \(destinationPath)") let dic = UIdocumentInteractionController() self.dic.URL = url let v = sender as UIVIEw let ok = self.dic.presentopenInMenuFromrect( v.bounds,inVIEw: v,animated: true)解决方法 将代码修改为以下内容
import UIKitclass VIEwController: UIVIEwController { var docController:UIdocumentInteractionController! overrIDe func vIEwDIDLoad() { let someText = Nsstring(string: "Test") if let documentsPath = NSSearchPathForDirectorIEsInDomains(.documentDirectory,true)[0] as? String { let destinationPath = documentsPath.stringByAppendingPathComponent("Data.txt") var error:NSError? let written = someText.writetofile(destinationPath,error: &error) if written{ println("Successfully stored the file at path \(destinationPath)") } if let url = NSURL(fileURLWithPath: destinationPath) { docController = UIdocumentInteractionController(URL: url) } } } @IBAction func sendfile(sender:AnyObject) { docController.presentoptionsMenuFromrect(sender.frame,inVIEw:self.vIEw,animated:true) }}
现在将IBAction连接到故事板中的按钮.下一个:
>单击左侧栏中的蓝色项目图标,然后选择
水平菜单中的信息.
>展开文档类型,然后在名称字段中输入“txt”
“类型”字段中的“public.data,public.content”
>现在展开导出的UTI并在描述中输入“txt”
字段,标识符字段中的“kUTTypeText”和
Conforms to字段中的“public.data,public.content”
所以一切都是这样的:
您现在可以构建并运行应用程序进行测试.
总结以上是内存溢出为你收集整理的ios – UIDocumentInteractionController()swift全部内容,希望文章能够帮你解决ios – UIDocumentInteractionController()swift所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)