The apple documentation made this seem like it was pretty easy but it’s not working. My code is:
UIActivityIndicatorView *activity = [[UIActivityIndicatorView alloc]initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
[activity startAnimating];
ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://www.myserver.com"]];
[request setPostValue:name forKey:@"key"];
[request startSynchronous];
NSLog(@"%@",[request responseString]);
[activity stopAnimating];
[activity release];
I didn’t set anything up in UIBuilder because frankly, I don’t understand exactly how it works with the UIActivityIndicator. Building and Running the app with the code I have above doesnt send off any warning indicators and runs just fine but I am not seeing the activity indicator.
The UI won’t update before finishing the method call (well or until the next iteration in the run loop to be more precisely), so this is effectively adding and removing it in the same step.
You should time your request asynchronously to see something happen, or at least schedule the different tasks (adding activity, the request itself and removing it) independently on the main thread. Blocking the main thread is a very bad idea though, and your app will get killed completely if your request takes too long to respond (for whatever reason – easy to think of with web services).