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.
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.
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."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With