views:

53

answers:

3

I have a working application

before the first view is loaded, i put an alert in the viewWillAppear method:

    - (void)viewWillAppear
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"MyAppp" message:@"Application will connect to Internet. Continue?"
                                               delegate:self cancelButtonTitle:nil otherButtonTitles:@"No, quit", @"Yes", nil];
    [alert show];    
    [alert release];
}

I can get the clicks on the two button (Yes/No) correctly...

But...I would like code execution to stop and wait for an answer, but instead the code goes on, connects to the internet and retrieves data...

How do I prevent a view to load, based on a user input?

+2  A: 

The viewWillAppear is a notification which allows you to complete some stuff before the view is shown, you can't avoid the appearing of the view here. You have to review your implementation.

Jorge
so, I found out that basically there's no way to show the UIAlertView modally (with the interruption of code)
Antonio
You can, but not in that event. UIAlertView does not stop the code execution. You should exit from the function you are showing the alert and continue with your routine in the UIAlertViewDelegate.
Jorge
+1  A: 

Just break your one viewWillAppear method into two methods. Don't try to do it all in one chunk of sequential code.

The first method will launch the alert and then just exit/quit/return.

The second method can be called by the alert button response handler, and then finish loading the view only after it's been called by the alert handler, after the user has responded.

You may or may not have to save extra state information (in extra properties or instance variables instead of method locals) between the first and second methods.

hotpaw2
A: 

I solved it by showing the answer in the "ViewDidLoad", got a delegate to get which button was pressed and then processing the data ONLY if the user pressed "Yes"

Antonio