Non-scroll overlay with UITableView - iOS

I have a UITableView class that uses the following methods to call a loading overlay when moving to the next screen. The problem is that this loading screen does not scroll through the list ... Therefore, if you scroll a little and click on something, the loading screen does not appear (because it is on top). How can I make the loading screen stay on top of the UITableView anytime? Keep in mind that every UITableView is contained in a UINavBar, which is contained in a UITabBar. Here is my code:

-(void)createLoadScreen
{
    CGRect screenRect = [self.view bounds];
    CGRect overlayFrame = CGRectMake(0.0, 0.0, screenRect.size.width, screenRect.size.height);
    overlay = [[UIView alloc] initWithFrame:overlayFrame];
    overlay.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
    CGRect frame = CGRectMake(screenRect.size.width / 2 - 25.0, screenRect.size.height / 2 - 70, 25.0, 25.0);
    loading = [[UIActivityIndicatorView alloc] initWithFrame:frame];
    [loading setActivityIndicatorViewStyle:UIActivityIndicatorViewStyleWhiteLarge];
    [loading sizeToFit];
    loading.autoresizingMask = (UIViewAutoresizingFlexibleLeftMargin |
                                UIViewAutoresizingFlexibleRightMargin |
                                UIViewAutoresizingFlexibleTopMargin |
                                UIViewAutoresizingFlexibleBottomMargin);
    loading.hidesWhenStopped = YES;
    [overlay addSubview:loading];
}

-(void)showActivityIndicator
{ 
    [self.view addSubview:overlay];
    [loading startAnimating];
}

-(void)removeActivityIndicator {
    [loading stopAnimating];
    [overlay removeFromSuperview];
}
+5
source share
1 answer

Are you using a UITableViewController?

, . ,

-(void)showActivityIndicator
{ 
    [[self.view superview] addSubview:overlay];
    [loading startAnimating];
}
+5

All Articles