断了的弦再谈一遍 2018-12-10 05:04 采纳率: 0%
浏览 1261
已结题

UIDocumentPickerViewController选取文件后无法继续present/push另外一个界面处理

页面结构为
TabBarController 》

//A 方法的作用是调用icloud选取文件
func A(){
  let picker = UIDocumentPickerViewController.init(documentTypes: ["public.data"], in: .import)
    pickerd.delegate = self
    self.present(picker, animated: true, completion: nil)
}

// documentPicker方法是pickerd.delegate回调的方法
func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    // 这里用通知是我原认为这个地方已经是处于present的模态窗口中,不能继续present,因为这个UIDocumentPickerViewController选取文件后会自己自动关闭,所以想着通知在另外一个地方中处理
      NotificationCenter.default.post(name: NSNotification.Name("selected"), object: self, userInfo:["urls": urls])
}

//selected方法是为了选取到icloud中文件后,想继续打开另外一个viewcontroller进行处理
@objc func selected(notification:NSNotification) {
    let userInfo = notification.userInfo

        guard let url = userInfo?["urls"] as? [URL] else {
            return
        }
        controllerB.url = url
   self.present(controllerB,animated: true, completion: nil))
}

现在的问题是,回调selected方法后, self.present 会提示Application tried to present modally an active controller,我想会不会是因为seleted方法也在TabBarController文件中,才会报错,但是事实上好像也不是这样,我也试过在A方法中再加一层navigationController,在seleted中用这个navigationController实例再做push,试验证明push是没报错,但是页面也并不会发生跳转,实在无解,求教。难道不能在UIDocumentPickerViewController拾取文件后再处理

  • 写回答

2条回答 默认 最新

  • BuyMinwoo 2018-12-10 06:39
    关注

    你可以试试 notification 的 addObserver 方法 接收了通知 自定义的传值

    评论

报告相同问题?

悬赏问题

  • ¥15 arduino控制ps2手柄一直报错
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥85 maple软件,solve求反函数,出现rootof怎么办?
  • ¥15 求chat4.0解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
  • ¥65 汇编语言除法溢出问题
  • ¥15 Visual Studio问题
  • ¥20 求一个html代码,有偿