Question

I copied the code to show the activity indicator from this post. When I called hideActivityViewer nothing happens, and the activityView is still there, and the activityIndicator is still spinning. It is as if hideActivityViewer does not do anything to the activityView at all.

Here is the code I have modified

-(void)showActivityViewer
{
    WBAppDelegate *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
{
    NSLog(@"Profile: hiding Activity Viewer");
    [[[_activityView subviews] objectAtIndex:0] stopAnimating];
    [_activityView removeFromSuperview];
    _activityView = nil;
}

Update: I'm using the KVO to detect for change in variable and use it to call showActivityViewer. Turns out, showActivityViewer was called more than once, as a result there are multiple activityViewer on the screen, so when I remove one, the other is still there and I have no to reference to it. I solved this by checking if the activityView already exist, and if so don't create a new one.

Was it helpful?

Solution

My comment as an answer:

It could be because activityView becomes nil at some point before a call to hideActivityViewer. Lets say u call showActivityViewer two times consecutively, you have two activityViews exactly on top of each other and the first one will never be hidden if you call hideActivityViewer. Even after matching number of hideActivityViewer calls, or more.

OTHER TIPS

You may be calling ur method "hideActivityViewer" from asynchronous or thread completion blocks. If so, call ur method on mainthread i.e
[self performSelectorOnMainThread:@selector(hideActivityViewer) withObject:nil waitUntilDone:NO];

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top