我有实现UIAlertViewDelegate的控制器。在实现中,我有:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex方法。当我创建委派时,我将“UIAlertView”设置为“self”,它工作得很好。但问题是,现在我又多了一个警报视图,我希望每个视图都有不同的行为。那么如何检查哪个alertView发送了消息呢?
发布于 2010-12-03 22:29:47
UIAlertView是一个UIView子类,因此具有标记属性,您可以使用它来区分它们:
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
}
}发布于 2010-12-03 22:27:48
指向每个特定警报视图的指针在委托方法的alertView参数中发送。您只需跟踪指针(例如,通过实例变量),就可以知道哪个是哪个,并采取相应的行动。
发布于 2010-12-03 22:29:53
UIAlertView创建了一个tag属性。当你创建它的时候设置它,你可以在代理中检查标签。
https://stackoverflow.com/questions/4346418
复制相似问题