★ TouchArcade needs your help. Click here to support us on Patreon.

Still learning (pt2) - How to change views

01-30-2009, 08:46 AM
#1
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Still learning (pt2) - How to change views

I had some great help with the first thread on forcing landscape, and now I am stuck on the next part of my project. As I have said before, I am waiting for my book to arrive (I have actually ordered another one today too), but until it does, I have been tinkering. I have got to the stage where I can create a single view, with useable buttons (my first project was a simple calculator). So I thought I would start on the main menu and settings views for what will be my first game. I have indeed created all the graphics for them, and have my main menu appearing when I start the app, with buttons for Play, Settings, Info- which have been allocated UIAction methods in the ControllerView files. I have created ControllerView files for the settings menu too, and I have defined the buttons and set a method for each, but so far I have nothing written in any of the button methods. Because what I want to do, for the moment at least, is allow the settings menu to appear when I tap the Settings button. And that's where I am stuck. I am finding it very hard to find any info online on how to actually set up different views and alternate between them. I would very much appreciate someone helping me to understand and answer these questions...

1)Do you use the one nib (.xib) file for all views, or do you create a seperate one for each? I can create a new nib file, but don't know if you are supposed to just use the one.

2)What command would I type in the UIAction method for the Settings button, in order to change to the Settings menu view?

Thank you in advance (I wish this bloomin' book would turn up fast!)
01-30-2009, 10:22 AM
#2
In brief, you'll need to create a new viewcontroller class for your settings, add a ViewController from the library to your .xib window. Add another view to that. Connect the controller to view. Set the controller to the class that you just made. Create an IBOutlet for that class in your menu and hook it up with a blue connector in IB. Then in your button action method call a line something like this. [self presentModalViewController:settingsViewController animated:Yes];

01-30-2009, 10:32 AM
#3
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Haha! That whole paragraph just flew straight over my head so fast I didn't even see it!

It'll take a while to digest that info and look into those settings in the IB. But basically you're saying I can use the same xib file anyway, right?
01-30-2009, 11:58 AM
#4
Quote:
Originally Posted by wastedyuthe View Post
Haha! That whole paragraph just flew straight over my head so fast I didn't even see it!

It'll take a while to digest that info and look into those settings in the IB. But basically you're saying I can use the same xib file anyway, right?
Correct, you'll be adding two things to it from the library. A UIViewController, and a UIView.
01-30-2009, 12:02 PM
#5
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Quote:
Originally Posted by Schenk Studios View Post
Correct, you'll be adding two things to it from the library. A UIViewController, and a UIView.
Aha! I was trying to find out how to add the view to the new ViewController. Of course! UIView in the Windows, Views, and Bars section of the library- drag it ONTO the new settings ViewController. Got it. Now I got to go through the rest.
What do you mean by 'connect the controller to view'?
01-30-2009, 12:20 PM
#6
Quote:
Originally Posted by wastedyuthe View Post
Aha! I was trying to find out how to add the view to the new ViewController. Of course! UIView in the Windows, Views, and Bars section of the library- drag it ONTO the new settings ViewController. Got it. Now I got to go through the rest.
What do you mean by 'connect the controller to view'?
I'll post a youtube vid in a bit that should make things clearer. Mixing the graphical programming of IB and the text programing of Xcode can make explanations tricky. :-D
01-30-2009, 12:22 PM
#7
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
Quote:
Originally Posted by Schenk Studios View Post
I'll post a youtube vid in a bit that should make things clearer. Mixing the graphical programming of IB and the text programing of Xcode can make explanations tricky. :-D
I hear ya! Thanks very much! For your information, in your quote below, I have marked the sections I am having trouble with in bold. I can do/have done the rest (although, is there anything I need to add to that line I call in the button method? It comes up with an error when I type that in, although that may be because I haven't done the rest of course).

Quote:
Originally Posted by Schenk Studios View Post
In brief, you'll need to create a new viewcontroller class for your settings, add a ViewController from the library to your .xib window. Add another view to that. Connect the controller to view. Set the controller to the class that you just made. Create an IBOutlet for that class in your menu and hook it up with a blue connector in IB. Then in your button action method call a line something like this. [self presentModalViewController:settingsViewController animated:Yes];

Last edited by wastedyuthe; 01-30-2009 at 12:25 PM.
01-30-2009, 01:30 PM
#8
Youtube wasn't playing nice. You can grab the vid off our website though.

http://www.schenkstudios.com/Downloads.html
01-30-2009, 01:57 PM
#9
Joined: Sep 2008
Location: Birmingham, UK, dull corner of the world
Posts: 2,367
WOW! Thank you so much for that vid! Seeing it done makes it so much easier. There were a few things that you did in IB, such as dragging the blue line to the Files Owner etc, that I didn't know. Also, when I tried, I dragged the UIView ONTO the SettingsViewController rather than next to it and dragging the blue line to it.

What you did in a few minutes will take me about 20, so I'll finish off after dinner. But I'll say thank you once again, as your tutorial video has helped immensely. Much appreciated
01-30-2009, 02:51 PM
#10
Glad I could help. If you run into problems, check capitalization and check your connections in IB.