UIAlertViewDelegate 和更多警报窗口

发布于 2024-10-06 01:18:55 字数 266 浏览 0 评论 0原文

我有实现 UIAlertViewDelegate 的控制器。在实现中我有:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

方法。当我创建 UIAlertView 时,我将“委托”设置为“自我”,它工作正常。但问题是,现在我多了一个警报视图,并且我希望每个视图都有不同的行为。那么如何检查哪个alertView发送了消息呢?

I have controller which implements UIAlertViewDelegate. In implementation I have:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

method. When I create UIAlertView I put for 'delegate' to 'self' and it works fine. But problem is that now I have one more alert views and I want different behaviors for each of them. So how to check which alertView send message?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

转瞬即逝 2024-10-13 01:18:55

UIAlertView 是 UIView 子类,因此具有可以用来区分它们的 tag 属性:

UIAlertView *alert1 = ... //Create alert
alert1.tag = kActionTag1;
//show alert

...

UIAlertView *alert2 = ... //Create alert
alert2.tag = kActionTag2;
//show alert

然后在委托方法中:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
     if (alertView.tag == kActionTag1){
          // Perform 1st action
     }
     if (alertView.tag == kActionTag1){
          // Perform 2nd action
     }
}

UIAlertView is a UIView subsclass and so has tag property you can use to differentiate between them:

UIAlertView *alert1 = ... //Create alert
alert1.tag = kActionTag1;
//show alert

...

UIAlertView *alert2 = ... //Create alert
alert2.tag = kActionTag2;
//show alert

And then in delegate method:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
     if (alertView.tag == kActionTag1){
          // Perform 1st action
     }
     if (alertView.tag == kActionTag1){
          // Perform 2nd action
     }
}
童话 2024-10-13 01:18:55

指向每个特定警报视图的指针在委托方法的alertView 参数中发送。您只需要跟踪指针(例如通过实例变量),以便您知道哪个是哪个并采取相应的行动。

The pointer to each specific alert view is sent in the alertView parameter of the delegate method. You simply need to track the pointers (for example through instance variables) so you know which is which and act accordingly.

愛放△進行李 2024-10-13 01:18:55

UIAlertView 气体标记属性。在创建时设置它,您可以在委托中检查该标签。

UIAlertView gas a tag property. Set it when you create it and you can check for the tag in the delegate.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文