Search code examples
iosuialertviewuialertcontrollerios9

How do i display UIAlertController from any NSObject subclass?


I have a legacy codebase I am managing, which needs to display alert messages from all over the place. This is terrible practice and is in need of a refactor, but that isn't going to happen any time soon. With iOS 9 I need the ability to fire & forget an alert view, and have the view display and queuing managed for me.


Solution

  • As other people have suggested, this is generally bad practice and breaks the MVC principles. However, if you're managing a legacy codebase and refactoring everything simply isn't an option, i made this class which lets you treat UIAlertController like the old UIAlertView, it manages displaying the alert from any class, and also queue's alerts for you...

    https://github.com/sammio2/SMHAlertController