2010-12-03 58 views
11

我有控制器实现UIAlertViewDelegate。在实施中我有:UIAlertViewDelegate和更多警报窗口

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

方法。当我创建UIAlertView时,我将'委托'放在'self'中,并且工作正常。但问题是,现在我有更多的警报视图,我想为他们每个人不同的行为。那么如何检查哪个alertView发送消息?

回答

12

UIAlertView中是一个UIView subsclass等方面有着你可以用它们来区分标签属性:

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 
    } 
} 
+0

谢谢,这有助于很多:) – 1110 2010-12-03 14:54:51

0

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

0

UIAlertView中气体的标记属性。在创建它时进行设置,并且可以检查委托中的标记。