如何从任何NSObject子类显示UIAlertController? [英] How do i display UIAlertController from any NSObject subclass?
问题描述
我有一个遗留的代码库正在管理,它需要显示来自各地的警报消息.这是很糟糕的做法,需要进行重构,但这不会很快发生.使用iOS 9时,我需要能够启动&忘记警报视图,并为我管理视图的显示和排队.
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.
推荐答案
正如其他人所建议的那样,这通常是不好的做法,并且违反了MVC原则.但是,如果您管理的是旧版代码库,而根本无法重构所有内容,那么我就创建了该类,使您可以像对待旧的UIAlertView
一样对待UIAlertController
,它可以管理显示任何类的警报,还可以对队列进行排队提醒您...
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
这篇关于如何从任何NSObject子类显示UIAlertController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!