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 8313769
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:36:16+00:00 2026-06-08T20:36:16+00:00

I have a singleton here is the header file: #import <Foundation/Foundation.h> @interface Shared :

  • 0

I have a singleton here is the header file:

#import <Foundation/Foundation.h>
@interface Shared : NSObject
{
     NSString *messages;
}
@property (nonatomic, retain) NSString *messages;

+ (Shared*)sharedInstance;

@end

Here is the implementation:

#import "Shared.h"
static Shared* sharedInstance;

@implementation Shared

@synthesize messages;


+ (Shared*)sharedInstance
{
    if ( !sharedInstance)
    {
        sharedInstance = [[Shared alloc] init];
    }
    return sharedInstance;
}

- (id)init
{
    self = [super init];
    if ( self )
    {
        messages = [[NSString alloc] init];
    }
    return self;
}
@end

The problem is when the I use

[Shared sharedInstance].messages = someVariable;

I can use
NSLog([Shared sharedInstance].messages);
and it shows the right output, but when i check from another class, NSLog doesn’t show any output. I have the NSLog in the viewDidLoad method of another class, so when I click a button to go to the next view, it should output the value of the string, but it only works the second time. If the variable is set to dog, first it outputs nothing, then when I close the view and try again, it outputs dog. however, if I then change the variable to cat, it will output dog, and on the next attempt, output cat. I want it to update immediately, rather than remain one behind all the time.

EDIT: Here’s the code from the other classes
This particular section is from a view controller class in the method

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
//Omitted, just preparing the DB, and emptying the array.
if ([db open])
    {
        FMResultSet *s = [db executeQueryWithFormat:@"SELECT ShabadID FROM Shabad WHERE Gurmukhi LIKE %@", currentLine];
        while ([s next])
        {
            lineID = [s intForColumn:@"ShabadID"];
        }
        s = [db executeQueryWithFormat:@"SELECT Gurmukhi, ShabadID FROM Shabad WHERE ShabadID LIKE %i", lineID];
        while ([s next])
        {

            //NSLog([s stringForColumn:@"Gurmukhi"]);
            [paragraphArray addObject:[s stringForColumn:@"Gurmukhi"]];
        }
        Text = @"";
        for (int i = 0; i<[paragraphArray count]; i++)
        {
            Text = [Text stringByAppendingFormat:@"%@\n", [paragraphArray objectAtIndex:i]];
        }
        [Shared sharedInstance].messages = Text;
    }

Then in the another class, where I want the text to appear, in the viewDidLoad method,

- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog([Shared sharedInstance].messages);
    UITextView *myUITextView = [[UITextView alloc] initWithFrame:CGRectMake(0,30,310,450)];
    myUITextView.text = [Shared sharedInstance].messages;
    myUITextView.textAlignment = NSTextAlignmentCenter;
    myUITextView.textColor = [UIColor blackColor];
    myUITextView.font = [UIFont fontWithName:@"GurbaniLipiLight" size:24];
    [myUITextView setBackgroundColor:[UIColor clearColor]];
    myUITextView.editable = NO;
    myUITextView.scrollEnabled = YES;
    [ScrollerView addSubview:myUITextView];
}

Sure the NSLog doesn’t show up right, but neither does the text in the textview, it does the same thing the NSLog does.

  • 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-08T20:36:18+00:00Added an answer on June 8, 2026 at 8:36 pm

    There is an assumption here about what order things happen in that’s not quite right. Assuming there’s a segue involved in this, didSelectRowAtIndexPath: is called after the new view controller is prepared but before it’s displayed. Moving code to viewWillAppear: or viewDidAppear: delays execution until after the calling controller has set new data.

    The other approach for communication between controllers that use a segue, is to use prepareForSegue: in the first controller to set data that the second controller needs. That way it should be available when the view is loaded.

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

Sidebar

Related Questions

I have a a singleton class here is the code #import <Foundation/Foundation.h> #import CustomColor.h
I have this singleton: UserData.h @interface UserData : NSObject { User *user; } +
I have a Singleton that is accessed in my class via a static property
I have a Singleton class here designed to be inherited by classes wanting to
I have a singleton class that is instantiated as follows: #import FavoritesManager.h static FavoritesManager
I have a singleton here that I am trying to use the same instance
Short Version: I define a property with (nonatomic, retain) and assumed that the property
I have a Singleton to manage some variables I need in various places in
I have a singleton class for global access to config information. This singleton class
I have a singleton object that use another object (not singleton), to require some

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.