I have an application which displays modal views. In the last modal view, I have a form. Upon clicking the done button, a web service is called which passes the values input from the user. After a response is received, the modal view is dismissed. I would like do display an alert or action sheet asking the user to wait as the web service call takes a lot of time. The problem is that the alert or action sheet gets displayed only after the view is dismissed. Why is this happening? Here is the code for the done function:
-(void)reg:(id)sender {
if([password length] == 0) {
//show alert
}
//other validation
//This is were I write the alert
UIActivityIndicator *activity = [[UIActivityIndicator alloc] initWithActivityIndicatorStyle:
UIActivityIndicatorStyleWhite];
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Processing" delegate:self otherButtonTitles:nil];
[alert addSubview:activity];
[activity startAnimating];
[alert show];
WebServiceController *web = [[WebServiceController alloc]init];
//webservice called
//getting the response
//dismissing alert here
[self dismissModalViewControllerAnimated:YES];
}
I got it. It wasn’t a problem with modal views. The alert gets blocked because the main thread is executing the web service. The web service execution needs to be run in the background. Here’s the link to a similar question with the answer.
Showing alert while calling webservice