0 Replies - 1173 Views - Last Post: 06 July 2011 - 08:24 AM

#1 Alhazred  Icon User is offline

  • D.I.C Head

Reputation: 9
  • View blog
  • Posts: 200
  • Joined: 25-July 07

Problem with activity indicator

Posted 06 July 2011 - 08:24 AM

On a view I have a button linked to this method
- (IBAction)performSearch:(id)sender {
	self.activityIndicator.hidden = FALSE;
	[self.activityIndicator startAnimating];

	NSMutableURLRequest *richiesta = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://www.sito.it/iosphp/responder.php"]
								cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:120.0];
	[richiesta setHTTPMethod:@"POST"];
	[richiesta setHTTPBody:[[NSString stringWithFormat:@"search=%@", self.textInput.text] dataUsingEncoding:NSASCIIStringEncoding]];
	NSURLResponse *response;
	NSError *error;
	NSData *dati = [NSURLConnection sendSynchronousRequest:richiesta returningResponse:&response error:&error];
	NSString *esitoRicerca = [[[NSString alloc] initWithData:dati encoding:NSASCIIStringEncoding] autorelease];
	[self.activityIndicator stopAnimating];
	self.activityIndicator.hidden = TRUE;
	if ([esitoRicerca isEqualToString:@"nodata"]) {
		self.labelEsito.text = @"Nessuna corrispondenza trovata";
		self.labelEsito.text = @"";
		TableResultsViewController *table = [[TableResultsViewController alloc] init];
		table.results = [esitoRicerca JSONValue];
		[self.navigationController pushViewController:table animated:YES];
		[table release];

In the php function called by this method I've put a 5 seconds pause to make it slow and see the activity indicator.

When I tap the button I can see the app wait the 5 seconds, but the indicator doesn't appear.

I've tried to remove the lines

[self.activityIndicator stopAnimating];
self.activityIndicator.hidden = TRUE;

going back to the main view the indicator is there spinning.
Why doesn't the indicator start as I tap the button, but after that the php function returns?

The problem is not the sync connection because I've tried changin the method in this way and I have the same problem
- (IBAction)performSearch:(id)sender {
    self.activityIndicator.hidden = FALSE;
    [self.activityIndicator startAnimating];
    [NSThread sleepForTimeInterval:5.0];

The indicator starts after 5 seconds as the code is not executed sequentially.

How to fix this?

Is This A Good Question/Topic? 0
  • +

Page 1 of 1