views:

284

answers:

2

Hello everyone!

I have created an alert view with two buttons using the following code:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: title 
message: msg delegate:nil cancelButtonTitle:@"Replay" otherButtonTitles:@"Highscore", nil];
[alertView show];

I want to run some code when one of the buttons is clicked. In order to do so, I have added the following method to the delegate.m file:

 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
 if (buttonIndex==0) //Run some code 
 else //Other code
 }

But this method is not called when I press either of the buttons! Can someone tell me why?

Thanks in advance,

Sagiftw

+2  A: 

Try setting the delegate to self instead of nil.

DyingCactus
+4  A: 
delegate:nil

how will the alert view associate a delegate if you specified there will be no delegates? Replace that part with

delegate:self

instead.

KennyTM
Thanks for the help! I forgot that!!! =)