tags:

views:

160

answers:

2

How can I make my delegate method wait until, user makes a choice to the alertview confirmation?

BOOL userChoice = FALSE;

I have this delegate method:

-(BOOL) returnUserChoiceYESorNO:(NSString*)message { //delegate method

UIAlertView *msgBox = [[UIAlertView alloc] initWithTitle:@"Your Choice" message:message delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"OK",nil]; [msgBox show]; [msgBox release];

//// HOW CAN I MAKE IT WAIT HERE, UNTIL I RECEIVE USER Responce from ClickedButtonAtIndex? (without using while loop or infinite loops)

return userChoice;

}

  • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if(buttonIndex==0) { userChoice = NO; else { userChoice = YES; }

}

A: 

Don't wait there for the dialog to return. It's a lot easier to pop up the alert, end your method, then wait around for the alert to return before you do whatever you need to do.

kubi
It is a DELEGATE Method. Once it calls, we need to respond immediately.
RealHIFIDude
A: 

You can't without loops. You shouldn't be stopping there if you can at all avoid it. What is calling your method? Can it be restructured to test for a value later, or can you rewrite things so that you can call back later with an answer?

Worst case, perhaps you could circumvent the code that is calling you, put up the dialog, cache the value and THEN create whatever conditions were going to cause the code to be called in the first place.

These GUI systems usually just aren't made to hang, they are made to return and have NO thread running most of the time. If you start circumventing that, you will end up with all sorts of threading and state issues.

Bill K