是否可以不关闭 UIAlertView
UIAlertviewDelegate 协议有几个可选方法,包括:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
这似乎表明并非所有按钮单击实际上都会关闭警报视图。但是,我看不到如何将警报视图配置为在按下任何按钮时不会自动关闭。
我是否必须创建一个子类才能完成此任务?
为什么 UIAlertViewDelegate 协议具有:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
并且
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
如果它不支持在每次单击按钮时不关闭警报视图?
简短的旁白: 我意识到 UIAlertView 的设计目的是什么。但我的目的是允许用户在应用程序退出之前将一些文本复制到粘贴板(当警报视图关闭时,这会自动发生)。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
willPresentAlertView:
、didPresentAlertView:
、alertView:willDismissWithButtonIndex:
和alertView:didDismissWithButtonIndex:
用于跟踪开始和结束UIAlertView 的动画结束。不需要跟踪 UIAlertView 动画的应用程序可以简单地使用
alertView:clickedButtonAtIndex:
。该方法的文档说“调用此方法后接收器将自动关闭”。willPresentAlertView:
,didPresentAlertView:
,alertView:willDismissWithButtonIndex:
, andalertView:didDismissWithButtonIndex:
are for tracking the start and end of UIAlertView's animations.Applications that don't need to track UIAlertView's animations can simply use
alertView:clickedButtonAtIndex:
. The docs for that method say "the receiver is automatically dismissed after this method is invoked."我认为:没有理由保留alertView。即使你想保留它,只要考虑“重新显示”它,通过保留引用,然后调用 [alertView show] ==> 无需子类化任何内容。好消息,是吧?
In my opinion: There's no reason to keep alertView. Even if you wanna keep it, just think about "re-show" it, by keeping a reference, then call [alertView show] ==> NO NEED TO SUBCLASS ANYTHING. Good news, huh?
子类化是最好的方法。创建一个
bool
标志来指示警报是否应该保留。这是
UIAlertView
的子类这就是我在代码中使用它的方式
Subclassing is the best way. Create a
bool
flag for alert should stay or not.This is the Subclass of
UIAlertView
And this is how I used it into my code
是的。子类
UIAlertView
,然后重载-dismissWithClickedButtonIndex:animated:
,例如非官方,您可以
为委托定义一个方法,使其绕过
-dismissWithClickedButtonIndex:animated:
,但它未记录,所以我不知道它是否适合你。Yes. Subclass
UIAlertView
and then overload-dismissWithClickedButtonIndex:animated:
, e.g.Unofficially you can define a
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.