Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIAlertView does not wait

I am using multiple UIAlertViews in my code as follows

-(void) myfunc
{ 
    myAlertView1 = [[UIAlertView alloc] initWithTitle:@"Message" message:[list objectAtIndex:1] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [myAlertView1 show];
    [myAlertView1 release], myAlertView1 = nil;
    {
        do something
    }
    myAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[list          objectAtIndex:1] delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [myAlertView show];
    [myAlertView release], myAlertView = nil;
}

When I run the program in simulator I see myAlertView1 (Message) briefly and it does not waits for Ok button click then I see myAlertView (Error) which waits for Ok button click and after that I again see myAlertView1 (Message) and it waits till OK button is clicked.

Logically I want to see myAlertView1(Message) and wait till Ok button is clicked and then see myAlertView (Error ) and wait till button is clicked. Am I missing something here?

like image 776
Manish Avatar asked Dec 23 '22 11:12

Manish


1 Answers

UIAlertView is not modal as one might expect. You should wait for your delegate to recieve alertView:didDismissWithButtonIndex: before creating and showing the second UIAlertView

like image 152
rpetrich Avatar answered Jan 05 '23 13:01

rpetrich