UIActivityIndicatorView is shown only after loading

I have a button in the current navigation controller view connected to IBAction.

In IBAction, I create a UIActivityIndicatorView, as usual, with [self.view addSubView], then upload some images.

I tried setNeedsDisplay in the indicator view, view controller and window, but it still uploads photos before the indicator displays, which, of course, is completely useless to me.

So, I'm looking for a way to force an instant redraw (which, when I think a little more about this is unlikely to do the job), or a way to load images after the indicator appears, or a way to start a separate thread or similar to start the animation / show the indicator, or put the indicator in a separate view manager and somehow make it add / show itself before moving on to loading the image.

Recommendations

+7
ios objective-c cocoa-touch loading uiactivityindicatorview
source share
1 answer

In this situation, I create a new thread that frees up the main thread for interacting with the user interface when the material is loaded in the background.

First show UIActivityIndicatorView , then create a new thread that loads the images, and then in the last line of the method that runs in the new thread, UIActivityIndicatorView .

Here is an example:

 //do stuff... [activityIndicatorView startAnimating]; [NSThread detachNewThreadSelector:@selector(loadImages) toTarget:self withObject:nil]; 

In your loadImages method:

 - (void) loadImages { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; //load images... [activityIndicatorView performSelectorOnMainThread:@selector(stopAnimating)]; [pool drain]; } 
+18
source share

All Articles