我有实现 UIAlertViewDelegate 的控制器。在实施中我有:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
方法。当我创建 UIAlertView 时,我将“委托”设置为“自我”,它工作正常。但问题是,现在我多了一个警报视图,并且我希望每个视图都有不同的行为。那么如何检查哪个alertView发送了消息呢?
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
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)