Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to NOT dismiss a 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.

like image 829
Corey Floyd Avatar asked Jan 12 '10 18:01

Corey Floyd


2 Answers

Yes. 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 

Unofficially you can define a

-(void)alertSheet:(UIAlertSheet*)sheet buttonClicked:(id)button; 

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.

like image 157
kennytm Avatar answered Sep 18 '22 15:09

kennytm


willPresentAlertView:, didPresentAlertView:, alertView:willDismissWithButtonIndex:, and alertView: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."

like image 33
Darren Avatar answered Sep 22 '22 15:09

Darren