从不同的ViewControllers调用UIAlertViewDelegate方法

时间:2012-01-05 15:01:37

标签: iphone uialertview

我的应用程序中的几个ViewControllers必须以相同的方式显示相同的UIAlertView并执行 - alertView:clickedButtonAtIndex:方法。我不想在几个文件中编写相同的代码,所以我需要一种具有一个alertView的全局UIAlertView:clickedButtonAtIndex:方法可用于我的所有ViewControllers。我创建了一个方法,在我的AppDelegate.m文件中调用UIAlertView并覆盖alertView:clickedButtonAtIndex:在同一个地方,但遗憾的是alertView:clickedButtonAtIndex:不会从不同的文件中调用。你有什么想法?谢谢你的时间

2 个答案:

答案 0 :(得分:2)

为什么不将UIViewController子类化为UIAlertView所需的所有功能,然后在当前子类AppDelegate上使用UIViewController cal方法在导航堆栈上。希望有帮助!

答案 1 :(得分:2)

在其他视图控制器中创建UIAlertView时,请确保将委托设置为AppDelegate(或者声明clickedButtonAtIndex:方法的地方)