0

I want to log if the user pressed OK on my alertView, but it's doing nothing... This is my check:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
    if (buttonIndex == 0) { NSLog(@"user pressed OK"); }
}

Also it's in my @interface:

@interface FirstViewController : UIViewController<UIWebViewDelegate, UIAlertViewDelegate>

And here's my alertView:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oeps..."
                                            message:@"This is just a random message."
                                            delegate:nil
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
[alertView show];

Does anyone see the problem? I tried to do an NSLog outside of the if buttonIndex but that won't be logged too..

Thanks

Gabriel.Massana
  • 8,165
  • 6
  • 62
  • 81
Joran Den Houting
  • 3,149
  • 3
  • 21
  • 51

3 Answers3

3

Instead of delegate being nil,assign your delegate as self

vin
  • 1,258
  • 5
  • 20
  • 33
2

Use the following:

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oeps..."
                                        message:@"This is just a random message."
                                        delegate:self
                                        cancelButtonTitle:@"OK"
                                        otherButtonTitles:nil];
[alertView show];
DogCoffee
  • 19,820
  • 10
  • 87
  • 120
Jasmin Mistry
  • 1,459
  • 1
  • 18
  • 23
1

Check your delegate you passed the delegate to nil. pass it to self thats whay this is happening...

like this

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oeps..."
                                            message:@"This is just a random message."
                                            delegate:self
                                            cancelButtonTitle:@"OK"
                                            otherButtonTitles:nil];
[alertView show];
Jitendra
  • 5,055
  • 2
  • 22
  • 42