我是iOS应用程序开发的新手,但我找不到类似的问题.
是否可以在同一个视图控制器中有两个或更多独特的警报?我的目标是iOS 7.1,因此使用以下不推荐使用的UIAlertView方法:
let errorAlert: UIAlertView = UIAlertView() errorAlert.delegate = self errorAlert.message = "Are you sure?" errorAlert.addButtonWithTitle("Yes") errorAlert.addButtonWithTitle("No") errorAlert.show()
此警报转到一个函数,该函数在switch语句中包含一些逻辑.
func alertView(View: UIAlertView!,clickedButtonAtIndex buttonIndex: Int) { ...
到目前为止一切都还可以,但是当我在同一个视图控制器中创建第二个警报时,它也会进入相同的功能.例如,如果我无法与数据库建立连接,我将显示不同的错误消息,但这也会转到上面的alertView函数并运行相同的switch语句.
我正在做一个明显的错误吗?
提前致谢.
解决方法
你可以尝试写这个:
func alertView(view: UIAlertView!,clickedButtonAtIndex buttonIndex: Int) { if view == errorAlert { // do your stuff.. } else if view == anotherAlertView { // do your stuff for the second AlertView } }