我有控制器实现UIAlertViewDelegate。在实施中,我有:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
方法。当我创建UIAlertView时,我将'委托'设置为'self'并且它工作正常。但问题是,现在我还有一个警报视图,我希望每个视图都有不同的行为。那么如何检查哪个alertView发送消息?
我有控制器实现UIAlertViewDelegate。在实施中,我有:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
方法。当我创建UIAlertView时,我将'委托'设置为'self'并且它工作正常。但问题是,现在我还有一个警报视图,我希望每个视图都有不同的行为。那么如何检查哪个alertView发送消息?
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
}
}
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
}
}
指向每个特定警报视图的指针在委托方法的alertView参数中发送。您只需要跟踪指针(例如通过实例变量),这样您就可以知道哪些是相应的并采取相应的行动。
UIAlertView gas是一个标签属性。在创建它时设置它,您可以检查委托中的标记。