是否可以不关闭UIAlertView [英] Is it possible to NOT dismiss a UIAlertView

查看:318
本文介绍了是否可以不关闭UIAlertView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIAlertviewDelegate协议有几个可选的方法,包括:

   - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex NSInteger)buttonIndex; 

这似乎暗示,并非所有按钮点击实际上都会关闭警报视图。



我必须创建一个子类才能完成此操作吗?



为什么UIAlertViewDelegate协议有:

   - (void)alertView:(UIAlertView * )alertView didDismissWithButtonIndex:(NSInteger)buttonIndex; 
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

AND

   - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex; 

如果没有选择性支持,每个按钮不关闭警报视图,请点击?



简介:
我意识到UIAlertView是为什么设计的。但我的目的是允许用户在应用程序退出之前将一些文本复制到粘贴板中(当警报视图被关闭时会自动进行。

解决方案

是。子类 UIAlertView ,然后重载 -dismissWithClickedButtonIndex:animated:

  @implementation MyAlertView 
- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated {
if buttonIndex不应该关闭警报)
return;
[super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}
@end






非正式,您可以定义

   - (void)alertSheet:(UIAlertSheet *)sheet buttonClicked:(id)button; 

方法到代理,这将绕过 -dismissWithClickedButtonIndex:animated:,但它未记录所以我不知道它是否适合你。


The UIAlertviewDelegate protocol has several optional methods including:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

This would seem to suggest that not all button clicks actually dismiss the alert view. However I see no way of configuring the alert view to NOT automatically dismiss with any button press.

Do I have to create a subclass to accomplish this?

Why would the UIAlertViewDelegate Protocol have:

- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex

AND

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;

If it didn't optionally support not dismissing the alert view with each button click?

Brief Aside: I realize what UIAlertView was designed for. But my purpose is to allow the user to copy some text to the paste board before the app exits (which happens automatically when the alert view is dismissed.

解决方案

Yes. Subclass UIAlertView and then overload -dismissWithClickedButtonIndex:animated:, e.g.

@implementation MyAlertView 
-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated {
   if (buttonIndex should not dismiss the alert)
      return;
   [super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}
@end


Unofficially you can define a

-(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(id)button;

method to the delegate which will make it bypass -dismissWithClickedButtonIndex:animated:, but it's undocumented, so I don't know whether it's suitable for you.

这篇关于是否可以不关闭UIAlertView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆