[英]present view controller in UIContentView
I'm having pageViewController(ABC) at rootViewController and pageViewController contains ViewController(PQR) Which contains ContentView. 我在rootViewController上有pageViewController(ABC),pageViewController包含包含ContentView的ViewController(PQR)。 I want to Present ViewController but it is saying
我想呈现ViewController,但这是说
Warning: Attempt to present XYZ: 0x17ee0730 on ABC: 0x17e67dc0 whose view is not in the window hierarchy!
警告:尝试在ABC:0x17e67dc0上显示XYZ:0x17ee0730,其视图不在窗口层次结构中!
On which controller I suppose to present View controller 我想在哪个控制器上呈现View控制器
Glad that your problem is solved. 很高兴您的问题得到解决。 Incase if you want to display alert, from any
UIView
other than a view controller, this would help. 如果您想通过视图控制器以外的任何
UIView
显示警报,这将有所帮助。
This method gets the top view controller, so that you can present your alert from it: 此方法获取顶视图控制器,以便您可以从中显示警报:
func currentTopViewController() -> UIViewController{
var topVC: UIViewController? = UIApplication.shared.delegate?.window??.rootViewController
while ((topVC?.presentedViewController) != nil) {
topVC = topVC?.presentedViewController
}
return topVC!
}
func showAlert() { // This presents your alert from the received view controller object
let alertController: UIAlertController = UIAlertController.init(title: "title", message: "message", preferredStyle: .alert)
let alertAction = UIAlertAction.init(title: "OK", style: .default) { (UIAlertAction) in
//Your action
}
alertController.addAction(alertAction)
currentTopViewController().present(alertController, animated: true, completion: nil)
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.