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

  • SEARCH
  • Home
  • 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 7929081
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T19:57:22+00:00 2026-06-03T19:57:22+00:00

I want to be able to refresh a view from another class, but nothing

  • 0

I want to be able to refresh a view from another class, but nothing I have tried is working. My application is a tabbed application with several tabs set up. I have a method called refresh in my ViewController1 class that looks like this

-(void)TestMe{


     NSString *filePath = [[NSBundle mainBundle] pathForResource:@"widgjson" ofType:@"json"];  
     NSData *myData = [NSData dataWithContentsOfFile:filePath];  

     NSString *responseString = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];

     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *docDir = [paths objectAtIndex: 0];
     NSString *docFile = [docDir stringByAppendingPathComponent: @"json.txt"];
     [responseString writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding error:Nil];

     [self loadView];
     [self viewDidLoad];
}

This works fine. When the application first loads up, it loads a different json, then when I click this button it loads a new JSON and then updates the view. This is just temporary to test out refreshing. However if I try to call this method from another class, or from the AppDelegates ApplicationDidEnterForeground methods, nothing happens. I tried calling it like this

 -(void)TestMe{


    ViewController1 *vc = [[ViewController1 alloc] init];


    NSString *filePath = [[NSBundle mainBundle] pathForResource:@"widgjson" ofType:@"json"];  
    NSData *myData = [NSData dataWithContentsOfFile:filePath];  

    NSString *responseString = [[NSString alloc] initWithData:myData encoding:NSUTF8StringEncoding];

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *docDir = [paths objectAtIndex: 0];
    NSString *docFile = [docDir stringByAppendingPathComponent: @"json.txt"];
    [responseString writeToFile:docFile atomically:NO encoding:NSUTF8StringEncoding error:Nil];

    [vc loadView];
    [vc viewDidLoad];

}

So why does this method not work from any other classes. All I want to is to be able to refresh a view from another class or when the application loads up, but just can’t seem to find anything that works.

Would be very grateful if someone could point me in right direction!

EDIT: UPDATING TO CLARIFY

Okay, what I have done for the time being which I don’t like is put this

exit(0);

Inside AppDelegates ApplicationDidEnterBackground. This works to an extent, but is not an ideal solution.

What I would like to have happen is that when application is opened again, the AppDelegate gets run again which sets up the tabs. The JSON pulled from the server can affect the order of the tabs which is why I need the AppDelegates ApplicationDidFinishLaunching method to reload itself again.

Also I would like to know can I do this from another class in the application. The first time my application is loaded it asks for the users phone number, which is sent to the server which then generates an PIN. After this is done, then I want the AppDelegate method to load up and begin setting up the tabs and the order etc.

  • 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-03T19:57:23+00:00Added an answer on June 3, 2026 at 7:57 pm

    To prevent your application running in the background (and so to force reloading when you exit and re-enter) you can set the UIApplicationExitsOnSuspend key to YES in your info.plist.

    However, this is probably a bit drastic.

    Your current code for refreshing from the application delegate is a non-starter because you are creating a new instance of the view controller rather than talking to one that is on the screen.

    For this reason it is best not to involve your application delegate at all in the process.

    Instead, your view controller can register itself as an observer for the UIApplicationDidBecomeActive notification, and do whatever it needs to itself. You would typically register for this notification on viewDidLoad, and unregister on viewDidUnload (since, by definition, if you have unloaded the view, you don’t need to refresh it when the app comes back up!).

    You would register as follows (using blocks here as they are the future):

    Declare an ivar of type id to hold the observer object, let’s call it becomeActiveObserver in this case. So, wherever you are declaring your ivars, add id becomeActiveObserver. Then, in viewDidLoad:

    becomeActiveObserver = [[NSNotificationCenter defaultCenter] 
    addObserverForName:UIApplicationDidBecomeActive 
    object:nil 
    queue: nil 
    usingBlock:^(NSNotification *note){ 
        //put your reloading code in here
        [self TestMe];
    }];
    

    And remove like so in viewDidUnload:

    [[NSNotificationCenter defaultCenter] removeObserver:becomeActiveObserver;
    

    You can follow a similar pattern to pick up notifications (your own, or system ones) from anywhere else in your app. This is a better design than passing everything through the app delegate as it involves much looser coupling.

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

Sidebar

Related Questions

There is a problem. I don't want that people would be able to refresh
I want to be able to refresh the page every 2 minutes so that
I have a purchase page and I don't want the user to be able
I have a web page which I want people to be able to upload
I want to be able to refresh an object by finding it's match in
I have the following code that I want to be able to loop every
I'm using LaTeX and BibTeX for an article, and I want to able to
Want to be able to provide a search interface for a collection of objects
I want to be able to bind an event to the axes in high
I want to be able to deply a jruby rails 3.1 app to Heroku.

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.