Pregunta

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

¿Fue útil?

Solución

Instead of delegate being nil,assign your delegate as self

Otros consejos

Use the following:

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

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];
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top