Can someone explain how the delegate to a UIAlertView
works? Is it automatically called or do I have to call it? Eg:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Let's say you showed an alert where the delegate was "self"
- (void)showAlert {
UIAlertView *myAlert = [[UIAlertView alloc] initWithTitle:@"My Alert"
message:@"Do you want to continue?"
delegate:self
cancelButtonTitle:nil
otherButtonTitles:@"No", @"Yes", nil];
[myAlert show];
[myAlert release];
}
In order for the following to work in your .m file:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
Your .h file will need to reference the UIAlertViewDelegate in the implementation statement like so:
@interface myViewController : UIViewController <UIAlertViewDelegate> {
}
This is what allows your .m file to respond to UIAlertViewDelegate method calls.
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