I have 3 classes. One is the class I show the loading view in(class A), one is the class I want to dismiss the loading view in(class B), and the last is the loading view object itself.
In classA I am able to show the loading view just fine by calling the showLoadingViewWithView: method I have displayed below, however when I get to classB and I want to dismiss that same loading view that I have created nothing happens.
Each method is called by creating an instance of the loading object, allocating memory to it, and then [object methodCall]; then release.
-(void)showLoadingViewWithView:(UIView *)currentView
{
CGRect transparentViewFrame = CGRectMake(0.0, 0.0,320.0,480.0);
loadingView = [[UIView alloc] initWithFrame:transparentViewFrame];
loadingView.backgroundColor = [UIColor grayColor];
loadingView.alpha = 0.9;
loadingSpinner = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
loadingSpinner.center = loadingView.center;
[loadingSpinner startAnimating];
UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 180, 320, 30)];
messageLabel.textAlignment = UITextAlignmentCenter;
messageLabel.text = @"Loading Please Wait...";
messageLabel.textColor = [UIColor whiteColor];
messageLabel.backgroundColor = [UIColor clearColor];
messageLabel.font = [UIFont boldSystemFontOfSize:15];
[loadingView addSubview:loadingSpinner];
[loadingView addSubview:messageLabel];
[currentView addSubview:loadingView];
[messageLabel release];
}
-(void)dismissLoadingView
{
[loadingSpinner stopAnimating];
[loadingView removeFromSuperview];
}
Any help would be awesome thanks.
Specialy when you are dealling with loading views indicators you often show the indicator in one place and need to notify it to close in another place. For this purpose (but not only) you should use NSNotifications. This is how you use it.
In class A you create a notification observer. Usually in the init method.
Then you need to impelemnt closeLoadingView: method to acctually close the view when the nottification arrives:
Always remeber to remove observers when you don’t need them. Usualy that happens in the dealloc.
Now in class B or from enywhere in your application you can close the view simply by sending a notification