i want display an activity indicator over a uitableview while it\'s loading data (in another thread). So in the ViewDidLoad method of the UITableViewController:
[iOS 5 +]
If you just want to show the activityWheel without an additional parentview, you can also add the activityWheel straight to the tableView and calculate the y value for the frame using the tableViews contentOffset:
@interface MyTableViewController ()
@property (nonatomic, strong) UIActivityIndicatorView *activityView;
@end
// ....
- (void) showActivityView {
if (self.activityView==nil) {
self.activityView = [[UIActivityIndicatorView alloc] initWithFrame:CGRectZero];
[self.tableView addSubview:self.activityView];
self.activityView.activityIndicatorViewStyle = UIActivityIndicatorViewStyleWhiteLarge;
self.activityView.hidesWhenStopped = YES;
// additional setup...
// self.activityView.color = [UIColor redColor];
}
// Center
CGFloat x = UIScreen.mainScreen.applicationFrame.size.width/2;
CGFloat y = UIScreen.mainScreen.applicationFrame.size.height/2;
// Offset. If tableView has been scrolled
CGFloat yOffset = self.tableView.contentOffset.y;
self.activityView.frame = CGRectMake(x, y + yOffset, 0, 0);
self.activityView.hidden = NO;
[self.activityView startAnimating];
}
- (void) hideActivityView {
[self.activityView stopAnimating];
}
If the activityView doesn't show up immediately (or never), refer to zirinisp's answer or do the heavy work in the background.