当我试图解散一个ViewController时,它是在一个嵌套在NavigationController中的ViewController中以编程方式呈现的,我似乎得到了一个
我的ViewController在嵌套的上面以模态方式呈现:
class RefreshController: UIViewController {
@IBOutlet var label: UILabel!
@IBOutlet var main: UIView!
@IBOutlet var spinner: UIActivityIndicatorView!
override func viewDidLoad() {
super.viewDidLoad()
spinner.startAnimating()
label.text = .localized("refreshing") + " ..."
main.layer.cornerRadius = 5
}
public func hideRefresh(_ contr: UIViewController, completion: @escaping (() -> Swift.Void)){
contr.presentedViewController?.dismiss(animated: true, completion: {
refreshController = nil
completion()
})
}
class func showRefresh(_ contr: UIViewController!, completion: @escaping (() -> Swift.Void)){
refreshController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "refreshController") as! RefreshController
contr.present(refreshController, animated: true, completion: {
completion()
})
}
}
我有一个全局变量refreshController,当它被显示为每次访问时,它将自己定义为当前呈现的控制器。
在嵌套的ViewController中,我调用:
refreshController.hideRefresh(self, completion: {
//code goes here, after the controller dismissed
}
(完成部分是由于动画,有时会与应该呈现的UIAlerts冲突)
有没有人有这方面的经验?或者它只是最新的iOS 10.2(14C82)测试版中的一个错误?
答案 0 :(得分:0)
在呈现的viewController上调用dismiss
,而不是在呈现的调用上:
public func hideRefresh(_ contr: UIViewController, completion: @escaping (() -> Swift.Void)){
// instead of contr.presentedViewController?.dismiss...
contr.dismiss(animated: true, completion: {
refreshController = nil
completion()
})
}