Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 04-21-2009, 08:27 PM   #1 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 12
Default How can I load a xib file from a menu

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
Negativi is offline   Reply With Quote
Old 04-21-2009, 08:55 PM   #2 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 12
Default

Help me please !
Negativi is offline   Reply With Quote
Old 04-21-2009, 09:13 PM   #3 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

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

Code:
MyGameController *game = [[MyGameController alloc] initWithNibName:@"MyGameView" bundle:nil];
[UIView beginAnimations:nil context:NULL]; 
[UIView setAnimationDuration:0.5]; 
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromRight forView:self.view cache:YES]; 
[self.view addSubview:game.view]; 
[UIView commitAnimations];
jsd is offline   Reply With Quote
Old 04-21-2009, 09:26 PM   #4 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 12
Default

@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.
Negativi is offline   Reply With Quote
Old 04-21-2009, 09:58 PM   #5 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 12
Default

Help me please !
Negativi is offline   Reply With Quote
Old 04-22-2009, 12:55 AM   #6 (permalink)
New Member
 
Join Date: Apr 2009
Posts: 12
Default

Help please !
Negativi is offline   Reply With Quote
Old 04-23-2009, 12:25 PM   #7 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

Quote:
Originally Posted by Negativi View Post
@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?
jsd is offline   Reply With Quote
Old 04-23-2009, 12:41 PM   #8 (permalink)
Registered Member
 
Join Date: Jan 2009
Location: Atlanta
Posts: 411
Default

Quote:
Originally Posted by jsd View Post
did you remember to put
Code:
#import "iTennisViewController.h"
at the top of your menu view controller's .m file?
What he said. It's not going to be able to "magically" know the view controller class... you have to include it.
funkytaco is offline   Reply With Quote
Old 04-24-2009, 05:51 PM   #9 (permalink)
So cunning its ridiculous
 
Join Date: Apr 2009
Age: 17
Posts: 135
Default

i used the code above but when you click the button in the simulator it says "__TERMINATING_DUE_TO_UNCAUGHT_EXCEPTION__"
why does this happen?
__________________
CunningCat
www.bigblueapps.webs.com
Baby Age Calulator
CunningCat is offline   Reply With Quote
Old 04-24-2009, 05:54 PM   #10 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

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.
jsd is offline   Reply With Quote
Old 04-24-2009, 06:06 PM   #11 (permalink)
So cunning its ridiculous
 
Join Date: Apr 2009
Age: 17
Posts: 135
Default

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController loadView] loaded the "MyGameView" nib but no view was set.'
__________________
CunningCat
www.bigblueapps.webs.com
Baby Age Calulator
CunningCat is offline   Reply With Quote
Old 04-24-2009, 06:13 PM   #12 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

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.
jsd is offline   Reply With Quote
Old 04-24-2009, 06:16 PM   #13 (permalink)
So cunning its ridiculous
 
Join Date: Apr 2009
Age: 17
Posts: 135
Default

its working now
thank you
__________________
CunningCat
www.bigblueapps.webs.com
Baby Age Calulator
CunningCat is offline   Reply With Quote
Old 06-19-2009, 05:38 AM   #14 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 7
Default

I tried all that was mentioned above but I am having trouble connecting the view outlet to my nib file.

When I drag a new referencing outlet from the view object towards file's owner, I am unable to.
Clementoe is offline   Reply With Quote
Old 06-19-2009, 01:13 PM   #15 (permalink)
jsd
at this moment
 
Join Date: Mar 2009
Location: San Francisco, CA
Posts: 900
Default

make sure your File's Owner is set to the correct object type.
jsd is offline   Reply With Quote
Old 06-20-2009, 12:53 AM   #16 (permalink)
New Member
 
Join Date: Jun 2009
Posts: 7
Default

that worked! Thanks ;P
Clementoe is offline   Reply With Quote
Reply

Bookmarks

Tags
game, load, menu, nib, xib

Thread Tools
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
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 272
16 members and 256 guests
@sandris, ADY, dacapo, Dani77, djohnson, HemiMG, JasonR, MarkC, mer10, nibeck, prchn4christ, ryandb2, spiderguy84, timle8n1, tomtom100
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,882
Threads: 89,229
Posts: 380,763
Top Poster: BrianSlick (7,129)
Welcome to our newest member, jansan
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 02:03 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0