Several UIAlertViews for a delegate(代表的几个 UIAlertViews)
问题描述
目前我有一个类在此处和那里弹出 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:代表的几个 UIAlertViews
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- URL编码Swift iOS 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- UITextView 内容插图 2022-01-01