Register FAQ / Rules Forum Spy Search Today's Posts Mark Forums Read
Go Back   MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jan 22, 2013, 05:43 PM   #1
lastcall
macrumors member
 
Join Date: Jan 2013
GameCenter question

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 by lastcall; Jan 22, 2013 at 08:27 PM.
lastcall is offline   0 Reply With Quote
Old Jan 28, 2013, 06:43 AM   #2
KoolStar
macrumors Demi-God
 
KoolStar's Avatar
 
Join Date: Oct 2006
Location: Kentucky
Send a message via AIM to KoolStar Send a message via Skype™ to KoolStar
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.
__________________
"Innovation distinguishes between a leader and a follower." : S.J.
KoolStar is offline   0 Reply With Quote
Old Jan 29, 2013, 03:45 PM   #3
lastcall
Thread Starter
macrumors member
 
Join Date: Jan 2013
Quote:
Originally Posted by KoolStar View Post
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 is offline   0 Reply With Quote
Old Jan 29, 2013, 07:29 PM   #4
lastcall
Thread Starter
macrumors member
 
Join Date: Jan 2013
Found something I can use:
self.navigationController.topViewController
lastcall is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > iPhone/iPad Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 08:22 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC