[英]swift Dismiss ViewController from a helper / another class
我尝试从查看器类中实例化的helperClass的功能中消除视图时遇到问题
public func set(playerController: AVPlayerViewController){
playerController?.dismiss(animated: true, completion: nil)
其视图不在窗口层次结构中!
如何正确传递控制器,以便助手类可以将其关闭?
查看者类别:
helper.add(player: player)
helper.set(playerController: playerController)
您应该能够从提供的视图控制器中执行dismiss(animated: true, completion: nil)
,因为Apple库可以处理来自主持人和提供的视图控制器的撤消。 无需传递参考
您还可以提供回调以消除以下内容:
helper.add(player: player) {
self.dismiss(animated: true, completion: nil)
}
Player:
public func set(playerController: AVPlayerViewController, completion: (Void)->Void){
completion()
}
在您的帮助程序类中尝试以下操作:-
AppDelegate.sharedInstance().window?.topMostController()?.dismiss(animated: true, completion: nil)
并将此功能添加到您的AppDelegate文件中:
class func sharedInstance() -> AppDelegate{
return UIApplication.shared.delegate as! AppDelegate
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.