Hello, I'm working on a game now, and I now need to add a menu for the game. So, my main view is my menu, with 1 button (The button "Play"), and i want to know how can I load the game xib file by clicking in this button ?
In my project I have 2 xib files (One for the menu, and one for the game). When I run the app in the iPhone Simulator, it shows me my menu. But when I click in my play button it does nothing. I want to open my game xib file when i click in this button.
I have created an action in my MenuViewController.H file, and linked that action to my button... and selected the option "Touch up Inside". The name of this action is "playGame:". and it is like this:
Quote:
- (IBAction)playGame: (id)sender;
I need help ! Please...
Sorry for bad english, Im brazilian.
Last edited by Negativi; 04-21-2009 at 08:29 PM.
Reason: Action showing as emoticon
you need to create a second view controller for the game. in the playGame: method you then transfer control to your second controller.
there's probably a better way, but this is the only one i've ever got to work without using a navigation controller. assumes your game controller is in a class called MyGameController and the view is in a nib file called MyGameView.xib
@jsd
Didnt work here. When I change my game controller to "iTennisViewController", wich is the real name of the game controller, I get an error: error: 'iTennisViewController' undeclared (first use in this function). And when i change my class controller to my menu view controller, it loads, but when i click on the play button, it closes the iPhone Simulator.
@jsd
Didnt work here. When I change my game controller to "iTennisViewController", wich is the real name of the game controller, I get an error: error: 'iTennisViewController' undeclared (first use in this function). And when i change my class controller to my menu view controller, it loads, but when i click on the play button, it closes the iPhone Simulator.
did you remember to put
Code:
#import "iTennisViewController.h"
at the top of your menu view controller's .m file?
what is the exception? (look in the debugger window)
it's impossible to guess without more information.
you could also try setting a symbolic breakpoint on objc_exception_throw and then looking at the debugger to see exactly which line in your code caused it to puke.
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController loadView] loaded the "MyGameView" nib but no view was set.'
you have to connect the view outlet in your nib file.
open up interface builder and load your xib
select the view object (next to file's owner & first responder).
press command-2 to open the connections inspector.
make sure under 'referencing outlets' you have the view outlet connected to file's owner.