Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

lastcall

macrumors member
Original poster
Jan 10, 2013
51
6
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?
 
Last edited:

KoolStar

macrumors demi-god
Oct 16, 2006
825
9
Kentucky
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.
 

lastcall

macrumors member
Original poster
Jan 10, 2013
51
6
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.

Thanks, that sounds like a good idea.

How do I determine what is the active view controller from the app delegate?
 

lastcall

macrumors member
Original poster
Jan 10, 2013
51
6
Found something I can use:
self.navigationController.topViewController
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.