目前我有一个类在此处和那里弹出 UIAlertView
.目前,同一个类是这些的代表(这将是非常合乎逻辑的).不幸的是,这些 UIAlertView
将调用该类的相同委托方法.现在,问题是 - 你怎么知道委托方法是从哪个警报视图调用的?我想只检查警报视图的标题,但这并不优雅.处理多个 UIAlertView
最优雅的方法是什么?
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!