【问题标题】:swift Dismiss ViewController from a helper / another class从助手/另一个类中快速解除 ViewController
【发布时间】:2017-10-13 05:05:54
【问题描述】:

当我尝试从查看器类中实例化的 helperClass 的函数中关闭视图时遇到问题

public func set(playerController: AVPlayerViewController){
playerController?.dismiss(animated: true, completion: nil)

谁的视图不在窗口层次结构中!

我怎样才能正确传递控制器,以便助手类可以关闭它?

查看者类:

helper.add(player: player)
helper.set(playerController: playerController)

【问题讨论】:

    标签: ios swift controller parameter-passing helper


    【解决方案1】:

    从你的助手类中试试这个:-

    AppDelegate.sharedInstance().window?.topMostController()?.dismiss(animated: true, completion: nil)
    

    并在您的 AppDelegate 文件中添加此功能:-

    class func sharedInstance() -> AppDelegate{
       return UIApplication.shared.delegate as! AppDelegate
    }
    

    【讨论】:

      【解决方案2】:

      你也可以给一个回调来解除 像这样:

      helper.add(player: player) {
       self.dismiss(animated: true, completion: nil)
      }
      
      Player:
      public func set(playerController: AVPlayerViewController, completion: (Void)->Void){
         completion()
      }
      

      【讨论】:

        【解决方案3】:

        您应该能够从呈现的视图控制器执行dismiss(animated: true, completion: nil),因为 Apple 库处理来自演示者和呈现的视图控制器的解雇。无需传递引用

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 2016-09-02
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-06-18
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多