UIAlertViewDelegate 和更多警报窗口
我有实现 UIAlertViewDelegate 的控制器。在实现中我有:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
方法。当我创建 UIAlertView 时,我将“委托”设置为“自我”,它工作正常。但问题是,现在我多了一个警报视图,并且我希望每个视图都有不同的行为。那么如何检查哪个alertView发送了消息呢?
I have controller which implements UIAlertViewDelegate. In implementation I have:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
method. When I create UIAlertView I put for 'delegate' to 'self' and it works fine. But problem is that now I have one more alert views and I want different behaviors for each of them. So how to check which alertView send message?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
UIAlertView 是 UIView 子类,因此具有可以用来区分它们的 tag 属性:
然后在委托方法中:
UIAlertView is a UIView subsclass and so has tag property you can use to differentiate between them:
And then in delegate method:
指向每个特定警报视图的指针在委托方法的alertView 参数中发送。您只需要跟踪指针(例如通过实例变量),以便您知道哪个是哪个并采取相应的行动。
The pointer to each specific alert view is sent in the alertView parameter of the delegate method. You simply need to track the pointers (for example through instance variables) so you know which is which and act accordingly.
UIAlertView 气体标记属性。在创建时设置它,您可以在委托中检查该标签。
UIAlertView gas a tag property. Set it when you create it and you can check for the tag in the delegate.