I'm using NSUrlConnection for accessing data from server. I want that during fetching of the data from the server the user interactivity is stopped as well as the code execution.
And I read more and more on Stack Overflow or Google, but I'm not get appropriate solution.
Please see the code which I'm using.
The first time when the user clicks to access the data from the server I start the activity indicator.
[activity startAnimating];
NSString *post =
[[NSString alloc] initWithFormat:@"Email=%@&Pass=%@",Email,pass];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSURL *url = [NSURL URLWithString:@"http://server.in/LoginStatus.php"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
[theRequest setHTTPMethod:@"POST"];
[theRequest setValue:postLength forHTTPHeaderField:@"Content-Length"];
[theRequest setHTTPBody:postData];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if( theConnection )
{
webData = [[NSMutableData data] retain];
}
else
{
}
and in the connectionDidFinishLoading
function I stop the activity indicator.
The problem is that when I check the returned data then it displays the previous result. When clicked again it display the proper result.
Please suggest if you have any idea.