【问题标题】:UIAlertView Delegate Protocol in iOSiOS 中的 UIAlertView 委托协议
【发布时间】:2014-09-08 01:53:34
【问题描述】:

我是iOS开发的初学者,昨天从Apple developer website了解了UIAlertViewDelegate协议。

我使用-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 来管理buttonindex 和执行特定任务。

但是,当我在同一个插座上使用 2 个UIAlertViews 时,它们都使用相同的UIAlertViewDelegate 协议。如何在我的应用程序中为另一个 UIAlertView 使用不同的委托?

另外,如何在我的应用程序中更改UIAlertView 的默认设计?

【问题讨论】:

    标签: ios uialertview uialertviewdelegate


    【解决方案1】:

    您的 UIAlertView 有一个名为 tag 的属性。实例化警报视图后,设置其标签:

    myAlertView.tag = 1;
    

    为每个警报视图使用不同的标记值。

    在你的回调方法中,首先检查标签以确定哪个警报视图被关闭并相应地处理:

    if (alertView.tag == 1) {
        //alert view 1 was dimissed, handle that
    } else if (alertView.tag == 2) {
        //alert view 2 was dismissed
    }
    

    【讨论】:

      猜你喜欢
      • 2021-03-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多