几个UIAlertViews代表 [英] Several UIAlertViews for a delegate
问题描述
目前,我有一个类在这里和那里弹出 UIAlertView
。目前,同一类是这些代表(这是合乎逻辑的)。不幸的是,这些 UIAlertView
将调用该类的相同代理方法。现在,问题是 - 你如何知道从哪个警报视图调用委托方法?我正在考虑只是检查警报视图的标题,但那不是那么优雅。什么是最优雅的方式来处理几个 UIAlertView
s?
Currently I've got a class popping up UIAlertView
s here and there. Currently, the same class is the delegate for these (it's very logical that it would be). Unfortunately, these UIAlertView
s will call the same delegate methods of the class. Now, the question is - how do you know from which alert view a delegate method is invoked? I was thinking of just checking the title of the alert view, but that isn't so elegant. What's the most elegant way to handle several UIAlertView
s?
推荐答案
标签 UIAlertView
这样:
#define kAlertViewOne 1
#define kAlertViewTwo 2
UIAlertView *alertView1 = [[UIAlertView alloc] init...
alertView1.tag = kAlertViewOne;
UIAlertView *alertView2 = [[UIAlertView alloc] init...
alertView2.tag = kAlertViewTwo;
然后在使用这些标签的委托方法中区分它们:
and then differentiate between them in the delegate methods using these tags:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
if(alertView.tag == kAlertViewOne) {
// ...
} else if(alertView.tag == kAlertViewTwo) {
// ...
}
}
这篇关于几个UIAlertViews代表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!