I want to display data loaded from a webservice but the webservice is taking a long time and the “data” is being displayed before it is loaded. How may I force it to wait?
Thanks.
Connection to web service
NSMutableURLRequest *theRequest=[NSMutableURLRequest requestWithURL:tmpURl];
[theRequest addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:@"http://tempuri.org/GetCategory" forHTTPHeaderField:@"SOAPAction"];
NSString *msgLength=[NSString stringWithFormat:@"%i",[soapMessage length]];
[theRequest addValue:msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPMethod:@"POST"];
[theRequest setHTTPBody:[soapMessage dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *conn=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(conn)
{
}
The
NSURLConnectionclass is asynchronous by default, there’s nothing in particular that you have to do to. I can see from the code snipped you’ve posted above that you are setting the delegate of theNSURLConnection, you just have to implement the methods required by the delegate.Have a look at the
NSURLConnectionclass reference, particularly the “Overview” section, where the delegate methods are explained.In your code snippet, after you start the connection, you can display an UIAlertView with a spinner for example, and dismiss it then in the delegate method when your data has arrived.