I have been trying to find a solution for that and have read a lot of forums, but i did not get what I wanted. After understanding how the activity indicator and table view controller works I came up with the following solution.
For some reason if you try to start the activity indicator on the same thread with the tableReload or any other expensive process, the activity indicator never runs. If you try to run table reload or some other operation in another thread then it might not be safe and might produce error or unwanted results. So we can run the method that presents the activity indicator on another thread.
I have also combined this solution with the MBProgressHUD to present something that look nicer that a view with an activity indicator. In any case the looks of the activityView can be customized.
-(void)showActivityViewer
{
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
UIWindow *window = delegate.window;
activityView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, window.bounds.size.width, window.bounds.size.height)];
activityView.backgroundColor = [UIColor blackColor];
activityView.alpha = 0.5;
UIActivityIndicatorView *activityWheel = [[UIActivityIndicatorView alloc] initWithFrame: CGRectMake(window.bounds.size.width / 2 - 12, window.bounds.size.height / 2 - 12, 24, 24)];
activityWheel.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhite;
activityWheel.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
UIViewAutoresizingFlexibleRightMargin |
UIViewAutoresizingFlexibleTopMargin |
UIViewAutoresizingFlexibleBottomMargin);
[activityView addSubview:activityWheel];
[window addSubview: activityView];
[[[activityView subviews] objectAtIndex:0] startAnimating];
}
-(void)hideActivityViewer
{
[[[activityView subviews] objectAtIndex:0] stopAnimating];
[activityView removeFromSuperview];
activityView = nil;
}
- (IBAction)reloadDataAction:(id)sender {
[NSThread detachNewThreadSelector:@selector(showActivityViewer) toTarget:self withObject:nil];
//... do your reload or expensive operations
[self hideActivityViewer];
}