One of my methods sends a message to the object (what you know about it), and awaits a BOOL response. However, the BOOL response that he expects is based on a response to the UIAlertView created in the method of the receiving object. However, the code does not stop waiting for the user to respond to the UIAlertView. My problem: how can I use -alertView: clickedButtonAtIndex in the returned method?
Here's the code the message is running in (in this construct, I expected navigateAwayFromTab to change based on user input in the UIAlertView, but never gets a chance):
- (BOOL)readyToNavigateAwayFromTab { NSLog( @"message received by Medical View"); navigateAwayFromTab = NO; UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Navigate Away From Tab?" message:@"Navigating away from this tab will save your work." delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK", nil ]; [alert show]; [alert release]; return navigateAwayFromTab; } #define CANCEL 0 #define OK 1 - (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex { if( buttonIndex == OK ) navigateAwayFromTab = YES; }
I read about the modal discussions of UIAlertView, and I agree with the apple implementation - as that is the rule. However, in this case, I see no way to solve the problem by putting the code in -alertView: clickedButtonAtIndex, because I do not need to run the code based on UIAlertView, I just need to read the answer. Any suggestions on how I can get to my prison? I already tried the while loop after [alert show], but then the warning does not even appear, and for a number of reasons I canβt use -viewWillDisapear.
Edit
For those who are considering this issue in the modern era, this question refers to ios 2
source share