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.
activityView
becomes nil at some point before a call tohideActivityViewer
. Lets say u callshowActivityViewer
two times, you have twoactivityView
s exactly on top of each other and the first one will never be hidden if you callhideActivityViewer
. Even after matching number ofhideActivityViewer
calls, or more. – RajivhideActivityViewer
? Do you see theNSLog()
results in the console? – Justin