Nested UIViewsControllers method calls

Discussion in 'iOS Programming' started by IDMah, Sep 30, 2013.

  1. IDMah, Sep 30, 2013
    Last edited: Sep 30, 2013

    IDMah macrumors 6502


    May 13, 2011
    Hi all.

    I have 2 UIViewControllers with tableviews. on a scrollview.

    UIController 0: is LocalHighScore.
    UIController 1: is GlobalHighScore.

    They have a method: loadHighScores: (int) where (int) tells it what file to load and reloads the data.

    How do call the Method(s) on Global HighScore controller from the top level UIViewController??
    ps. Global HighScore is offscreen. (does that even matter?)

  2. Duncan C macrumors 6502a

    Duncan C

    Jan 21, 2008
    Northern Virginia
    It depends on how your app is structured. How do you load the global high score view controller? Do you create it with a segue, and let it get released when you move to a different VC? Or do you create your GlobalHighScore VC at launch and keep it around?

    One option is to make your loadHighScores method a class method rather than an instance method. That way you can call it even if there is not currently an instance of the GlobalHighScore in memory.

    Another option would be to move those methods out of your VCs and into a singleton utilities class.
  3. IDMah thread starter macrumors 6502


    May 13, 2011
    Why not wait for sync to happen ???

    Quick and dirty answer was to Create something that tells the View
    Which HighScore Screen it was on:

    NSInteger highScoreIdent;
    // and then also add in View //
    - (void)viewDidLoad
     // Stuff and more Stuff // 
    // then did //
     [super viewDidLoad];
        [[NSNotificationCenter defaultCenter] addObserver:self
    -(void) reloadHighScores
        if (highScoreIdent>0) {
            [self loadHighScores:1]; 
            // which loads the data from"worldHighScoreTable"
    // And then when the Server Load Push the Notification // 
    - (void)fetchedData:(NSData *)responseData 
      // get all the stuff // 
     //  and when done // 
      [[NSNotificationCenter defaultCenter] postNotificationName:@"PLEASEVIEWTOUPDATE" object:nil];
    Why I couldn't think of this before also Stumps me... feels a little Hacky but works..

    Hope this Helps someone else..
    but more than likely you're smarter than me. HAHaha!!!

    Thanks everyone.
  4. Guiyon macrumors 6502a

    Mar 19, 2008
    North Shore, MA
    Any reason why you can't trigger the refresh in viewWillAppear:/viewDidAppear:?
  5. IDMah thread starter macrumors 6502


    May 13, 2011
    It's was more about waiting for the data to load from the server.
    and then reloading the nsuserdefaults, might have been able to use that
    but this makes sense to my little brain.

    Also differentiating between the LocalHighsScore and GlobalHighScore

Share This Page