GameCenter question

Discussion in 'iOS Programming' started by lastcall, Jan 22, 2013.

  1. lastcall, Jan 22, 2013
    Last edited: Jan 22, 2013

    lastcall macrumors member


    Jan 10, 2013
    I have a navigation-type app where you start with a root viewController, and other views get pushed
    onto the stack.

    Question is, if my app uses Game Center in more than one view, should I allocate my GameCenter manager
    as a singleton, so I can access it from everywhere, or should I allocate a new instance per view?

    The problem I have with using a singleton, is that my GameCenter manager requires that
    I setup a delegate. But, only one view can be set as its delegate. So, if I were to use it with
    multiple views, it would mean I would have to change the delegate everytime I change the view.
    Is this safe to do? Does it follow any kind of design practice?
  2. KoolStar macrumors demi-god


    Oct 16, 2006
    If you have a navigation controller that pushes views that all use Game Center, you could have the class that creates the Navigation Controller be the delegate. In this case I assume the app delegate. You could then use the call back in the app delegate to grab the navigation controllers current view controller that would allow you handle events in that class alone. Therefore you would only set the delegate once and which ever view you were on would get the forwarded event form the app delegate.
  3. lastcall thread starter macrumors member


    Jan 10, 2013
    Thanks, that sounds like a good idea.

    How do I determine what is the active view controller from the app delegate?
  4. lastcall thread starter macrumors member


    Jan 10, 2013
    Found something I can use:

Share This Page