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

    IDMah

    Joined:
    May 13, 2011
    #1
    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?)

    thanks.
     
  2. Duncan C macrumors 6502a

    Duncan C

    Joined:
    Jan 21, 2008
    Location:
    Northern Virginia
    #2
    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

    IDMah

    Joined:
    May 13, 2011
    #3
    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:

    Code:
    HighScoreController.h
    NSInteger highScoreIdent;
    
    
    HighScoreController.m
    // and then also add in View //
    
    - (void)viewDidLoad
    {
     // Stuff and more Stuff // 
    // then did //
     [super viewDidLoad];
        [[NSNotificationCenter defaultCenter] addObserver:self
                                                 selector:@selector(reloadHighScores)
                                                     name:@"PLEASEVIEWTOUPDATE"     
                                                    object:nil];
    
    }
    
    -(void) reloadHighScores
    {
        if (highScoreIdent>0) {
            [self loadHighScores:1]; 
            // which loads the data from"worldHighScoreTable"
        }
    }
    
    // And then when the Server Load Push the Notification // 
    
    HighScoreGetter.m
    
    - (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

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

    IDMah

    Joined:
    May 13, 2011
    #5
    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
    thanks
    Ian
     

Share This Page