Activity indicator not showing

I have two questions with an activity indicator: 1. The activity indicator is not displayed on the UIViewController

I have an activity indicator added to a .xib file. When a button is pressed, it should start the animation. and when receiving a response from the server, before moving to the next page, it should stop the animation. I do it as follows:

activityIndicator.hidden = NO; [activityIndicator performSelector:@selector(startAnimating) withObject:nil afterDelay:0.1]; [self.view bringSubviewToFront:activityIndicator]; ....rest of code here.... activityIndicator.hidden = YES; [activityIndicator stopAnimating]; 
  • Activity indicator not showing in UITableView

To represent the table, I do it the same way, but on didselectrowatindexpath ...

For tableview, I also tried to add an activity view to the cellular accessory, but still did not display

In both cases, the activity indicator is not displayed.

Please, help

thanks

+4
source share
3 answers

If all of this code is in a single method or in response to a single event, none of the changes in the views will be displayed until you return to the event loop. You set the ActivityIndicator.hidden value to NO, and then set it to YES again until the user interface is even able to update.

You also apparently stop the animation before starting it.

What you need to do is show an activity indicator and start its animation. Then plan the work to be done (start an asynchronous network connection or put some work in the queue or something you need to do) and return from this method so that the user interface can be updated, the indicator can be drawn, and the animation can begin.

Then at some point after the work is completed, you can hide the indicator and stop the animation. But you cannot do all this in the main thread in one turn of the event loop. None of your changes will be visible, because no drawing will occur at all here while this method is executed (if it is in the main thread)

Hope this makes sense?

+11
source

Now I changed the code to this:

 activityIndicator.hidden = NO; [activityIndicator startAnimating]; [self performSelector:@selector(saveClicked) withObject:nil afterDelay:0.1]; [self.view bringSubviewToFront:activityIndicator]; 

and it worked :)

+2
source

Maybe in tableView instead of self.view it will be self.navigationController.view ??

+1
source

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


All Articles