I have a UITableViewController which is a RootViewController. It has only a tabular view. I add the UIActivityIndicator identifier through IB and create an IBOutlet. I programmatically added a toolbar with a delete button to the RootViewController. When the user clicks the delete button on the toolbar, I want to display an indicator in the center of the screen. The method below deletes data from the database, which happens very quickly. I want the user to know that something is happening. If I run the code below without sleep (), this happens quickly and I do not see the indicator. But some, for some reason, I do not see the indicator in any case. I assume sleep () blocks repainting? If I survive the dream () and the last two lines, I see the indicator, but, of course, it never disappears. It is also displayed in the upper left corner of the window.
How can I get the code below to work so that the indicator displays for at least 1/2 second?
How to align the indicator in the middle of the window?
[self.navigationController.view addSubview:activityIndicator];
[activityIndicator startAnimating];
[activityIndicator setNeedsDisplay];
sleep(1);
[activityIndicator stopAnimating];
[activityIndicator removeFromSuperview];
source
share