Comments (4)
Your issue is probably due to the alert being presented twice. modalPresentationStyle = UIModalPresentationStyle.overCurrentContext
covers the current context, meaning that if you have one alert displayed, this alert will cover your UIViewController
view normally.
In the case where you are showing two alerts at the same time, the current context alert is the first alert, which is after dismissed, creating this black background since the only view remaining now is your UITabBarController
view, which is, if you didn't set a color to it, is black.
This issue usually occurs because when you use self.present(myAlertController, animated: true, completion: nil)
, the alert is displayed on top of your view, which is itself displayed on top of the UITabBarController
view, whom UITabBarItems
remaining active and usable. By that, you can still use the app and trigger other AlertControllers producing that issue.
I have been looking to understand how the native UIAlertController
could cover the whole UIWindow
when calling present to it without success from now.
As @Burakpusat suggested:
guard let rootVC = UIApplication.shared.keyWindow?.rootViewController else {
return }
rootVC.present(showAllSeasonVC, animated: true, completion: nil)
should be enough to fix your issue.
Intrigued to know why you get that error you mentioned.
Another solution would be to present the alert directly on the UITabBarController
, which is a UIViewController
subclass, which also would fix your issue.
As seen on your screenshot, you don't have a UINavigationController, so the direct parent of your UIViewController is the UITabBarController.
You can now grab it using the parent
property on your UIViewController and calling parent?.present(hnAlertViewController, animated: true, completion: nil)
In the case you are using a UITabBarController
+ UINavigationController
, using a simple recursive function can bring you to the UITabBarController
:
......
guard let tabBarController = findTapBar(from: self) else { return }
tabBarController.present(hnAlertViewController, animated: true, completion: nil)
}
func findTapBar(from child: UIViewController?) -> UITabBarController? {
if child == nil {
return nil
}
if let tabBarController = child?.parent as? UITabBarController {
return tabBarController
}
return findTapBar(from: child?.parent)
}
}
Hope it solves your issue.
from pmalertcontroller.
I've came across with this before and actually saw a suggestion below -cannot reference since I couldn't find the original post-
guard let rootVC = UIApplication.shared.keyWindow?.rootViewController else {
return }
rootVC.present(showAllSeasonVC, animated: true, completion: nil)
This solves the problem but of course Paolo might have better suggestions.
from pmalertcontroller.
Thanks for your suggestion, I've tried to use this code but in my architecture it doesn't open the alert because " the vc is not in the window hierarchy". So I don't understand how modify the code.
from pmalertcontroller.
I think that @florianldt explained well how to solve the problem.
Feel free to reopen the issue if it's not solved for any reason.
from pmalertcontroller.
Related Issues (20)
- Lots of Xcode 10 errors HOT 2
- Change Button Colour When Selected HOT 3
- Send notification on alert dismiss
- Not presenting nested Alerts HOT 1
- How to show buttons horizontally? HOT 5
- Invalid Task Error after Pod Install HOT 9
- Turning off auto dismiss when tapping button HOT 2
- Can I keep the alert portrait even though the view is in landscape? HOT 2
- Require textfield value HOT 3
- xcode10.2 build error HOT 2
- Can I override the viewDidDisappear method in PMAlertController HOT 1
- PMAlertController textfield access via objc HOT 4
- Build error when not using dynamic framework in podfile
- Swift Compiler Error in Swift 5 HOT 2
- Display two alertVC
- Can't Set Attributed String
- How to customize like fonts?
- App Store Connect operation error HOT 2
- Missing SPM Support HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pmalertcontroller.