Reputation: 9830
I have a UIAlertView
that I implemented in viewDidLoad
. I'm trying to make the alertView
stay when the otherButton
(buttonAtIndex:1
) was selected. Here is my code:
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];
}
When the second button was selected ("Done"), the alertView
goes away. How can I make it stay?
Upvotes: 0
Views: 148
Reputation: 3763
You should create your own alert view class that is NOT a subclass of UIAlertView. UIAlertView's documentation, it says under 'Subclassing notes:
The UIAlertView class is intended to be used as-is and does not support subclassing. (...)
Above referenced in UIAlertView
Apple Documentation section marked Subclassing Notes
Upvotes: 2
Reputation: 504
You might have what you want 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
Upvotes: -1