views:

544

answers:

2

I have implemented a UIActivityIndicator that shows up in one part of my program but not another. I have the activity indicator come up while i am loading a table, however, i am trying to get it to start animating again after the user has clicked a button and is waiting for the table to reload. The table reloads, but no indicator. Here is the code.

- (void)viewWillAppear:(BOOL)animated {

CGRect frame = CGRectMake (120.0, 185.0, 80, 80);
activity = [[UIActivityIndicatorView alloc] initWithFrame: frame];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;
[activity startAnimating];

[navigationUpdateFromDetail.window addSubview: activity];

[super viewWillAppear:animated];
}

It comes up for that part. However, for the next part it does not want to seem to come up.

- (IBAction) btnGreaterTen_clicked :(id)sender{

self.searchDistance = [NSNumber numberWithDouble : 10];

CGRect frame = CGRectMake (120.0, 185.0, 80, 80);

activity = [[UIActivityIndicatorView alloc] initWithFrame: frame];
activity.activityIndicatorViewStyle = UIActivityIndicatorViewStyleGray;

[navigationUpdateFromDetail.window addSubview: activity];
[activity startAnimating];


NSLog(@" search value after change %@", [searchDistance description]);

[self getSetDisplay];

[activity stopAnimating];

}

That button changes a variable and is suppose to start the animation, but it does not. I have changed the color to make sure it was not just blending in, so that is not the solution. I tried to recreate the same object, but still no luck. Thank you in advance.

A: 

try adding

activity.hidden = NO;

just before

[activity startAnimating];
Nithin
tried that, did not quite do it. thank you though
Makinitez21
+2  A: 

That won't work, because the animation will only show when the main application loop is "running". In your code, you're blocking the main thread by calling [self getSetDisplay].

You should load your data asynchronously to make this work (in a background thread). Then you can call startAnimating, start your thread, and when the thread finishes, stop the animation.

Philippe Leybaert
im not quite sure what you mean by loading it in the background, I call [self getSetDisplay] after starting the animation. Isnt the main thread running its loop then?
Makinitez21
From what you are saying, it makes sense cause the first activity indicator is called in the -viewWillAppear method which is running on the main loop. My functions are not. So do i need to implement a different function all together?
Makinitez21
This solution is correct. I removed the [self getSetDisplay] function and kept the activity indicator running and it popped up. but im still at a loss as to how to fix it.
Makinitez21
Check this question: http://stackoverflow.com/questions/1879248/http-request-using-threading-from-iphone or check out the threading documentation on Apple's developer site:http://developer.apple.com/iPhone/library/documentation/Cocoa/Conceptual/Multithreading/Introduction/Introduction.html
Philippe Leybaert
Thank you, I got the implementation for the "performinbackground" class, however i cannot seem to find how to monitor for the call back. How exactly do you know its done?
Makinitez21