让 UIAlertView 停留

Make UIAlertView stay

我在 viewDidLoad 中实现了 UIAlertView。当 otherButton (buttonAtIndex:1) 被选中时,我试图让 alertView 保持不变。这是我的代码:

UIAlertView *dialog = [[UIAlertView alloc] initWithTitle:@"Title"
                      message:@"Message:"
                      delegate:self cancelButtonTitle:@"Cancel"
                      otherButtonTitles:@"Done", nil];

[dialog setAlertViewStyle:UIAlertViewStylePlainTextInput];
[dialog show];


- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex
{
    if (buttonIndex == 1) return;
    [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
}

选择第二个按钮 ("Done") 时,alertView 消失。我怎样才能让它留下来?

你可能有你想要的here :

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

您应该创建自己的警报视图 class,它不是 UIAlertView 的子class。 UIAlertView 的文档,它在“Subclassing notes:

下说

UIAlertView class 旨在按原样使用,不支持子classing。 (...)

以上内容在 UIAlertView Apple Documentation 标记为 Subclassing Notes 的部分中引用