iphone - 是否可以不关闭 UIAlertView

标签 iphone cocoa-touch uialertview

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/

相关文章:

iphone - 专注于 iPhone 上的下一个有效按键 View

ios - 在 didReceiveLocalNotification 中以编程方式关闭 UIAlertview

iphone - ARC 中的 '[[something retain] autorelease]' 是什么?

ios - Objective-C 在没有相机界面的情况下拍摄照片的简单方法。只需从相机中获取照片并保存到文件中

ios - 可选链上的 EXC_BREAKPOINT

ios - MKAnnotation 的唯一性

swift - 无论我做什么,NSLayoutManager 都会隐藏换行符

ios - otherbuttontitles,如何取值

ios - UIAlertView 警报在长按手势识别器中重复三次

ios - 准备转至 UITabBarController 选项卡