UIAlertviewDelegate 协议(protocol)有几个可选方法,包括:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
这似乎表明并非所有按钮单击实际上都会关闭警报 View 。但是,我看不到如何将警报 View 配置为在按下任何按钮时不会自动关闭。
我必须创建一个子类才能完成此任务吗?
为什么 UIAlertViewDelegate 协议(protocol)会有:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex;
- (void)alertView:(UIAlertView *)alertView willDismissWithButtonIndex:(NSInteger)buttonIndex
并且
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex;
如果它不支持在每次单击按钮时不关闭警报 View ?
简要说明: 我意识到 UIAlertView 的设计目的是什么。但我的目的是允许用户在应用程序退出之前将一些文本复制到粘贴板(当警报 View 关闭时会自动发生。
最佳答案
是的。子类 UIAlertView
,然后重载 -dismissWithClickedButtonIndex:animated:
,例如
@implementation MyAlertView
-(void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated {
if (buttonIndex should not dismiss the alert)
return;
[super dismissWithClickedButtonIndex:buttonIndex animated:animated];
}
@end
<小时/>
非正式您可以定义一个
-(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(id)button;
委托(delegate)的方法将使其绕过-dismissWithClickedButtonIndex:animated:
,但它未记录,所以我不知道它是否适合您。
关于iphone - 是否可以不关闭 UIAlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2051402/