views:

125

answers:

1

I'm a beginner with Objective C and iPhone development.

It's there any way to call methods from the view controller from any class in my project ?

I began writting a small openGL game, beginning from the EAGLview generated by the default opengl project that Xcode allows me to create. The game so far works well, but I would like to call methods from the ViewController from my game class, for example, call some methods which use the GameKit framework that I wrote in my ViewController.

It's there any way to make It happen ?, or I'm doing it wrong and there is a different aproach which I should use ?

A: 

You can either

1) Pass in a pointer down your chain of objects and views so that you can pass it messages in the controller
2) Setup a global variable that points to the view controller
3) Consider extracting the relevant code in your view controller into another class, then using this class in both places.

I would lean towards 3 if I were you as it is cleanest and scaleable.

coneybeare
Thanks for Your help.Just Another question..since I'm trying to use the GameKit framework, it's possible for me to use it from any class ?, all the examples I see declare methods to implemment the P2P funcionality inside an UIViewController ?, such as GameControler: : UIViewController <GKPeerPickerControllerDelegate, GKSessionDelegate, UIAlertViewDelegate> ...thanks !
José Joel.
You can pull logic out where ever you want. It is really beyond the scope of this question though...
coneybeare