I am trying to call and alert when a button is pressed. i use this :
-(IBAction)Add { UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"add button pressed" message:@"Add to record" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil ]; [alert show]; [alert release]; }
ok , no problem here, two button came up, OK and cancel. Now i want detect which button is pressed i use:
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { // the user clicked one of the OK/Cancel buttons if (buttonIndex == 0) { //just to show its working, i call another alert view UIAlertView *alert = [[UIAlertView alloc] initWithTitle: @"OK WORKIng well" message:@"no error" delegate:nil cancelButtonTitle:@"IWORKS" otherButtonTitles:@"NO PRB", nil]; [alert show]; [alert release]; } else { NSLog(@"cancel"); } }
now here is the problem. i cannnot detect which button is pressed; the 2nd alertview doesnt show. i've check through the code a couple of times, there doesn't seem to be any problem with it. no error/warning too.
To detect the button clicks the alert view must have an associated delegate, e.g.
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"add button pressed" message:@"Add to record" delegate:self // <------ cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil];
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