Can't get a spinner to appear

I would like to use a counter. But this code below does not display a spinner, and I'm not sure why. How to do it? BTW, This is the one called from the submit button that 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]; } 
+4
source share
3 answers

If you call some lock code immediately after the counter is displayed, the user interface will not be updated, because it is updated only when the main run cycle starts. If this is really the source of the problem, a counter should appear when you comment out the [request startSynchronous] for the test.

The solution is to use an asynchronous request. The delegation code looks like you already did, but on the other hand, a synchronous operation is mentioned in the start call. Take care of this? (Or am I missing something?)

+14
source
 //spinner declared in .h file UIActivityIndicatorView *aSpinner; 

Add the property to the header file as well:

 @property (nonatomic, retain) UIActivityIndicatorView *aSpinner; 

Remember to synthesize the .m file!

 //throw up spinner from submit btn we created UIActivityIndicatorView *tempSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; self.aSpinner = tempSpinner; [tempSpinner release]; [self.view addSubview:self.aSpinner]; [self.aSpinner startAnimating]; //send blocking request [request startSynchronous]; //get rid of spinner when finished delegate is fire - (void)requestFinished:(ASIHTTPRequest *)request { NSLog(@"REQUEST FINISHED"); [self.aSpinner stopAnimating]; } 

In your dealloc method you write: [aSpinner release]; This, however, is only one of many approaches.

+3
source

The problem may be that you are adding a counter. Is it capable, and is it sized to display an activity indicator? (e.g. UIBarButtonItems cannot handle addSubview)

0
source

Source: https://habr.com/ru/post/1334098/


All Articles