问题描述: 在不同的入口点中创建的UIAlertController不会显示在层次结构中。
解决方法: 这个问题的原因是UIAlertController必须在当前可见的视图控制器中显示。下面是一些解决方法:
if let rootViewController = UIApplication.shared.keyWindow?.rootViewController {
rootViewController.present(alertController, animated: true, completion: nil)
}
if let viewController = UIApplication.shared.windows.first?.rootViewController?.presentedViewController {
viewController.present(alertController, animated: true, completion: nil)
}
if let viewController = UIApplication.shared.windows.first?.rootViewController?.presentingViewController {
viewController.present(alertController, animated: true, completion: nil)
}
请根据你的具体情况选择适合的方法来显示UIAlertController。这些方法可以确保UIAlertController正确显示在屏幕上。