ios - How to pass a value from a delegate to another one in swift? -
i want pass url in documentpicker previewcontroller. since of them delegates, can't return because violate protocol. how pass data view view? thanks!
func previewcontroller(controller: qlpreviewcontroller!, previewitematindex index: int) -> qlpreviewitem! { //var doc = nsurl(fileurlwithpath: url) return doc } func documentpicker(controller: uidocumentpickerviewcontroller, didpickdocumentaturl url: nsurl) { println("\(url)") var quickview = qlpreviewcontroller() quickview.datasource = self presentviewcontroller(quickview, animated: true, completion: nil) }
~~~~~~~~~~~update~~~~~~~~~6.2~~~~~~~~~~~~~~ follow idea of answer follow
func documentpicker(controller: uidocumentpickerviewcontroller, didpickdocumentaturl url: nsurl) { println("\(url)") var a: string = "\(url)" nsuserdefaults.standarduserdefaults().setobject(a, forkey: "url") var quickview = qlpreviewcontroller() quickview.datasource = self presentviewcontroller(quickview, animated: true, completion: nil) }
and
func previewcontroller(controller: qlpreviewcontroller!, previewitematindex index: int) -> qlpreviewitem!{ var url = nsuserdefaults.standarduserdefaults().objectforkey("url") as! string var doc = nsurl(fileurlwithpath: url) return doc }
by doing avoid format issue of nsuserdefaults, program still break @ doc (thread 1: breakpoint 1.1)
for example, when run , select file, url file:///private/var/mobile/containers/data/application/dee5190d-6e3f-4400-8866-4668b830c588/tmp/documentpickerincoming/experiment_7.pdf
and doc : optional(file:/private/var/mobile/containers/data/application/dee5190d-6e3f-4400-8866-4668b830c588/tmp/documentpickerincoming/experiment_7.pdf -- file:///)
they same. why app break?
well can store url in nsuserdefaults
. , use whenever want. can store text in nsuserdefaults
func documentpicker(controller: uidocumentpickerviewcontroller, didpickdocumentaturl url: nsurl) { println("\(url)") nsuserdefaults.standarduserdefaults().setobject(url, forkey: "url") var quickview = qlpreviewcontroller() quickview.datasource = self presentviewcontroller(quickview, animated: true, completion: nil) }
and retrieve in
func previewcontroller(controller: qlpreviewcontroller!, previewitematindex index: int) -> qlpreviewitem! { var doc = nsuserdefaults.standarduserdefaults().objectforkey("url") as! nsurl return doc }
Comments
Post a Comment