Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9213383
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:44:11+00:00 2026-06-18T01:44:11+00:00

Possible Duplicate: What should my Objective-C singleton look like? I am trying to understand

  • 0

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:-)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:44:12+00:00Added an answer on June 18, 2026 at 1:44 am

    I can appreciate your goal to understand singletons better, but I would suggest not using a singleton unless you have to.

    I don’t think it is appropriate in most UI scenarios(I have never needed one) to have singletons. I suggest one of the following methods for communicating between objects:

    • Hold a reference to objects that you want to communicate with. Simply add a property and save a reference to the class that needs to be called later. You can make it a weak reference if it works in your scenario.

    • Use the delegate pattern that is common with iOS/Objective-c apps. Same as above, except define a protocol instead. Normally the property is called delegate. This allows other views to communicate using a common interface.

    • Use notification center. I don’t prefer this option for most cases, but if there is an event that a lot of views might need to know about, and you don’t want to deal with passing references to objects, it might be a good option.

    Singletons work best for non-UI code in my experience, when you actually need to rely on the singleton behavior of instantiating the class upon first use. In your situation it looks like the only reason you’re using a singleton is to make that view controller accessible across your entire app.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Should I Use self Keyword (Properties) In The Implementation? Say I have
Possible Duplicate: Should I always use accessors for instance variables in Objective-C? Lets suppose
Possible Duplicate: Difference beetween _ and self. in Objective-C Should I use self.tableView or
Possible Duplicate: Should I use foreign keys? Ok, let's assume we have two tables,
Possible Duplicate: Should I use != or <> for not equal in TSQL? Behavior
Possible Duplicate: Should C++ eliminate header files? In languages like C# and Java there
Possible Duplicate: Why should I use templating system in PHP? I was just curious
Possible Duplicate: When should one use final? When should Java programmers prefer to use
Possible Duplicate: Should I prefer to use literal syntax or constructors for creating dictionaries
Possible Duplicate: Should I use Java's String.format() if performance is important? I was wondering

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.