Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can’t get a spinner to appear

I would like to use a spinner. But, this code below does not display a spinner and I'm not sure why. How to make this work? BTW, It is being called from a submit button I created.

//spinner declared in .h file
UIActivityIndicatorView   *aSpinner; 

//throw up spinner from submit btn we created
aSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:
    UIActivityIndicatorViewStyleWhiteLarge];

[self.view addSubview:aSpinner]; 
[aSpinner release]; 
[aSpinner startAnimating]; 

//send blocking request 
[request startSynchronous];

//get rid of spinner when finished delegate is fired
- (void)requestFinished:(ASIHTTPRequest *)request 
{ 
    NSLog(@"REQUEST FINISHED"); 
    [aSpinner stopAnimating]; 
    //[aSpinner release]; 
} 
like image 522
iPhone Developer Avatar asked Dec 03 '22 10:12

iPhone Developer


1 Answers

If you call some blocking code immediately after you display the spinner, the UI won’t get updated, since it only updates when the main run loop is running. If this really is the source of the problem, the spinner should show up when you comment out the [request startSynchronous] line for a test.

The solution would be to use an asynchronous request. The delegating code looks like you already do that, but on the other hand the start call mentions synchronous operation. Care to explain? (Or did I overlook something?)

like image 94
zoul Avatar answered Jan 15 '23 01:01

zoul