本文介绍了UIAlertViewDelegate和更多警报窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有控制器实现UIAlertViewDelegate。在实现中我有:
I have controller which implements UIAlertViewDelegate. In implementation I have:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
方法。当我创建UIAlertView时,我将'委托'设置为'self'并且它工作正常。但问题是,现在我还有一个警报视图,我希望每个视图都有不同的行为。那么如何检查哪个alertView发送消息?
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?
推荐答案
UIAlertView是一个UIView子类,因此有标签属性可以用来区分他们:
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
然后在委托方法中:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if (alertView.tag == kActionTag1){
// Perform 1st action
}
if (alertView.tag == kActionTag1){
// Perform 2nd action
}
}
这篇关于UIAlertViewDelegate和更多警报窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!