Is the UIActivityIndicator malfunctioning?

I have a problem with UIActivityIndicator. I put [spinner startAnimating]a button on IBAction, and then I executed some process. After the process activity pointer has to be stopped, then go to another view. But the activity indicator does not appear. When I delete the line "[spinner stopAnimating]", then the indicator appears, but the instant button is not pressed. It appears just before the other view is loading and, apparently, does not appear, I mean that it does not appear, but if we see very carefully, only it appears for a moment.

Thanx in advance for any answer.

+3
source share
4 answers

Ole is pretty much true, but there is a trick that you don't mind synchronous processing (often because you want to display an activity indicator in the first place).

First, move your code that you want to process, while the counter works according to its own method. Then do

[spinner startAnimating];
[self performSelector:@selector(methodname) withObject:nil afterDelay:0];

AfterDelay: 0 means next time through a run loop. Thus, the rotation begins.

+11
source

The animation will not start until your code returns control of the run loop. If your processing task blocks the main thread, UI updates will not be performed until they are completed. You must do your processing asynchronously (e.g. by running NSOperation).

+4
source

you must start the selector.

for ex:

[self performSelector:@selector(animation) withObject:nil afterDelay:0]

-(void)animation

{

NSAutoreleasepool *pool = [[NSAutorepleasepool alloc]init];

[indicatorView startAnimating];

[pool release];

}
+4
source

This is an old question. I am leaving my answer here to help someone solve their problem.

0
source

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


All Articles