Possible Duplicate:
What should my Objective-C singleton look like?
I am trying to understand the use of singletons. I have red to be careful with them, but also that they can have their positive uses.
My Scenario:
At the moment I have a test Project set up. One ViewController has a button that needs to perform an action.
The FirstViewController has a UIWebView on it.
I am using Storyboard and ContainerView, so I am able to see both ViewControllers at the same time.
In the First ViewController I have this code in my .m file:
static FirstViewController *sharedController = nil;
+ (FirstViewController *)sharedController {
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
//BBCSermonTabBarViewController *myVC = (BBCSermonTabBarViewController *)[storyboard instantiateViewControllerWithIdentifier:@"BBCNews"];
if(sharedController == nil)
sharedController = (FirstViewController *)[storyboard instantiateViewControllerWithIdentifier:@"firstViewController"];
return sharedController;
}
And I also have a method that changes the alpha it like so:
-(void)hideWebView
{
_webView.alpha = 0.3;
}
Now in my Second View controller I have this code:
-(IBAction)hideWebViewFromAnotherViewController
{
[[FirstViewController sharedController] hideWebView];
}
Should that action button now change the alpha of the webView in the other ViewController?
if not what am I doing wrong??
Thanks in advance:-)