不同的警报视图和视图控制器
在同一个视图控制器中,我必须显示不同的警报以及由警报按钮触发的不同操作(此视图控制器是警报的委托)。
有没有办法重用警报代码 init/show/release。
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
考虑到我需要区分警报,
In a same view controller, I have to show different alerts with different actions triggered by the alert buttons (this view controller is the delegate of the alerts).
Is there a way to reuse the alert code init/show/release, considering that in
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
I need the alerts to be distinguishable.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
正是 7KV7 所说的。您需要标记警报视图,并在事件处理程序中检查发件人的标记是什么。这样,您可以在同一事件处理程序 (clickedButtonAtIndex) 中为不同的警报视图创建不同的操作。
Exactly what was stated by 7KV7. You need to tag the alert view, and check in your event handler what the sender's tag was. This way, you can create different actions for different alert views in the same eventhandler (clickedButtonAtIndex).
您可以定义一组常量来表示您正在管理的每种不同类型的警报视图。例如:
然后,每当您发现自己需要呈现 UIAlertView 时,调用一个包装 init/show show 代码并设置 UIAlertView 标签的方法:
然后,在alertView:clickedButtonAtIndex: 中,您可以检查警报的标签查看传入的内容并做出相应的响应。
You can define a set of constants to represent each different type of alert view you're managing. For instance:
Then, whenever you find yourself needing to present a UIAlertView, call a method that wraps up the init/show show code and sets the tag of the UIAlertView:
Then, in alertView:clickedButtonAtIndex: you can check the tag of the alert view passed in and respond accordingly.
您可以在此处获取警报视图
You can get the alert view here itself