I have a working code from a tutorial but donโt understand it completely.
Situation:
After clicking a button in the iPhone app, AlertView with three buttons appears. Now I like to check which button the user clicked.
MANUAL CODE:
- (IBAction)infoButtonPressed:(id)sender { UIAlertView *myAlert1 = [[UIAlertView alloc]initWithTitle:@"My Alert View 1" message:@"Here we go" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Option1", @"Option2", nil]; [alert show]; } - (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { NSLog(@"Button: %i, was pressed.", buttonIndex); }
The code works, I see the correct output in the console as NSLog, but how is it possible that the method:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { NSLog(@"Button: %i, was pressed.", buttonIndex); }
refers to the correct presentation of the warning. In this case: myAlert1.
How about more than one view. For example, the second caller is myAlert2.
I know that the following code is incorrect, but it would be more useful for me if I write a method as follows:
- (void)alertView:(UIAlertView *)alertView didDismissWithButtonIndex:(NSInteger)buttonIndex { NSLog(@"Button: %i, was pressed.", buttonIndex_FROM_myAlert1); }
Hope you can help, drive me crazy.
Regards, Mark
user1010563
source share