Code Monkey home page Code Monkey logo

Comments (4)

florianldt avatar florianldt commented on June 11, 2024 2

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.

Burakpusat avatar Burakpusat commented on June 11, 2024

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.

grosetti avatar grosetti commented on June 11, 2024

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.

pmusolino avatar pmusolino commented on June 11, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.