I have a UITableViewController, which is RootViewController. It's XIB only has a table view. I've add a UIActivityIndicator through IB and created an IBOutlet. I've programmatically added a toolbar with a delete button to the RootViewController. When the user clicks the toolbar's delete button, I want to display the indicator, centered on the screen. The method below deletes data from a database, which happens very fast. I want to let the user know something is happening. If I run the code below without sleep(), it happens to fast and I don't see the indicator. But some for some reason, I'm not seeing the indicator anyways. I'm guessing sleep() blocks repainting? If I take out sleep() and the last two lines, I see the indicator but of course it never goes away. It also displays in the top left of the window.
How do I get the code below to work so that the indicator displays for 1/2 - 1 second at least?
How do I align the indicator in the middle of the window?
[self.navigationController.view addSubview:activityIndicator];
[activityIndicator startAnimating];
[activityIndicator setNeedsDisplay];
//do something which might happen really fast
sleep(1); //create illusion
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];